Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Oreo Issues Has Been Resolved. #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
applicationId "com.ahmedjazzar.rosetta.app"
minSdkVersion 14
targetSdkVersion 23
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "0.9.3"
}
Expand All @@ -20,12 +20,12 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.7.22'

compile project(':rosetta')
implementation project(':rosetta')
}
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
package="com.ahmedjazzar.rosetta.app">

<application
android:name=".MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".MainApplication" >
android:theme="@style/AppTheme">

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/ahmedjazzar/rosetta/app/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.ahmedjazzar.rosetta.app;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;

import com.ahmedjazzar.rosetta.ContextWrapper;

import java.util.Locale;

public abstract class BaseActivity extends AppCompatActivity {
SharedPreferences mSharedPreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this method if it doesn't contain changes.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeeshanrasool91 Any updates ion this?


}

@Override
protected void attachBaseContext(Context newBase) {
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(newBase);
Locale locale = new Locale(mSharedPreferences.getString("user_preferred_language", "en"));
Context context = ContextWrapper.wrap(newBase, locale);
super.attachBaseContext(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

import java.util.Locale;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);

// This floating button switching between Arabic and English Locales manually upon click
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
final FloatingActionButton fab = findViewById(R.id.fab);
setSupportActionBar(toolbar);

if (MainApplication.languageSwitcher.getCurrentLocale().getLanguage().equals("ar")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.ahmedjazzar.rosetta.app;

import android.app.Application;
import android.content.Context;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all these unused imports?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeeshanrasool91 Any updates on these?

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.ahmedjazzar.rosetta.ContextWrapper;
import com.ahmedjazzar.rosetta.LanguageSwitcher;

import java.util.HashSet;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was actually showing me transparent view on my Lollipop device.

</style>
</resources>
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:3.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using this repository?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is required by Latest Compat Libraries

}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
#Thu Jun 21 17:34:17 PKT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
30 changes: 16 additions & 14 deletions rosetta/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ext {
siteUrl = 'https://github.com/ahmedaljazzar/rosetta'
gitUrl = 'https://github.com/ahmedaljazzar/rosetta.git'

libraryVersion = '1.0.1'
libraryVersion = '1.0.2'

developerId = 'ahmedaljazzar'
developerName = 'Ahmed Jazzar'
Expand All @@ -29,11 +29,12 @@ buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
}

Expand All @@ -45,12 +46,12 @@ android {
maven { url 'http://repo1.maven.org/maven2' }
}

compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
minSdkVersion 15
targetSdkVersion 27
versionCode 3
versionName "1.0.1"
}
Expand All @@ -64,11 +65,12 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
compile 'com.android.support:appcompat-v7:23.1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.7.22'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.jakewharton:process-phoenix:2.0.0'
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to comment, just remove the line.

//apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to comment as well, just remove the line.

2 changes: 1 addition & 1 deletion rosetta/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ahmedjazzar.rosetta">

<application android:supportsRtl="true" />
<application android:supportsRtl="true"/>
</manifest>
42 changes: 42 additions & 0 deletions rosetta/src/main/java/com/ahmedjazzar/rosetta/ContextWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.ahmedjazzar.rosetta;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.LocaleList;

import java.util.Locale;

public class ContextWrapper extends android.content.ContextWrapper {

public ContextWrapper(Context base) {
super(base);
}

public static ContextWrapper wrap(Context context, Locale newLocale) {

Resources res = context.getResources();
Configuration configuration = res.getConfiguration();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
configuration.setLocale(newLocale);

LocaleList localeList = new LocaleList(newLocale);
LocaleList.setDefault(localeList);
configuration.setLocales(localeList);

context = context.createConfigurationContext(configuration);

} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLocale(newLocale);
context = context.createConfigurationContext(configuration);

} else {
configuration.locale = newLocale;
res.updateConfiguration(configuration, res.getDisplayMetrics());
}

return new ContextWrapper(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.widget.Button;
import android.widget.TextView;

import com.jakewharton.processphoenix.ProcessPhoenix;

import java.util.ArrayList;
import java.util.Locale;

Expand Down Expand Up @@ -153,7 +155,8 @@ protected void onPositiveClick() {
getActivity(), mSelectedLanguage)) {

mLogger.info("App locale changed successfully.");
LocalesUtils.refreshApplication(getActivity());
//LocalesUtils.refreshApplication(getActivity());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when i was using your refresh method the problem was that it was recreating application and current activity both.
i just wanted to recreate whole application. so it can recreate all resources in my application

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool with me, but just no need to comment, removing the line is enough.

ProcessPhoenix.triggerRebirth(getActivity());
} else {
mLogger.error("Unsuccessful trial to change the App locale.");
// TODO: notify the user that his request not placed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.support.v4.app.FragmentActivity;
import android.util.DisplayMetrics;

import com.jakewharton.processphoenix.ProcessPhoenix;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -265,7 +267,8 @@ static boolean setLocale(Locale newLocale, Activity activity) {
}

if (LocalesUtils.setAppLocale(activity.getApplicationContext(), newLocale)) {
LocalesUtils.refreshApplication(activity);
//LocalesUtils.refreshApplication(activity);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when i was using your refresh method the problem was that it was recreating application and current activity both.
i just wanted to recreate whole application. so it can recreate all resources in my application

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool with me, but just no need to comment, removing the line is enough.

ProcessPhoenix.triggerRebirth(activity);
return true;
}

Expand Down