Skip to content

Commit

Permalink
switch to api 23 (Android 6.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
miku-nyan committed Dec 7, 2015
1 parent 74c45cc commit 3eb8b6d
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 18 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="22" />
android:targetSdkVersion="23" />

<application
android:name="nya.miku.wishmaster.common.MainApplication"
Expand Down
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.android.tools.build:gradle:1.3.1'
}
}

Expand All @@ -23,11 +23,10 @@ dependencies {
}

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
compileSdkVersion 23
buildToolsVersion "23.0.2"

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
android.useDeprecatedNdk=true
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-22
target=android-23
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import nya.miku.wishmaster.http.streamer.HttpStreamer;
import nya.miku.wishmaster.lib.base64.Base64;
import nya.miku.wishmaster.ui.AppearanceUtils;
import nya.miku.wishmaster.ui.ResourcesCompat23;

import org.apache.commons.lang3.tuple.Pair;
import cz.msebera.android.httpclient.Header;
Expand Down Expand Up @@ -153,7 +154,7 @@ public void run() {
if (message != null) {
TextView textView = new TextView(activity);
textView.setText(message);
textView.setTextAppearance(activity, android.R.style.TextAppearance);
ResourcesCompat23.setTextAppearance(textView, android.R.style.TextAppearance);
textView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
rootLayout.addView(textView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
//import android.support.v7.appcompat.R;
import nya.miku.wishmaster.ui.ResourcesCompat23;

/**
* A drawable that can draw a "Drawer hamburger" menu or an Arrow and animate between them.
Expand Down Expand Up @@ -77,7 +78,7 @@ abstract class DrawerArrowDrawable extends Drawable {
color = typedValue.data;
} else {
try {
color = context.getResources().getColor(typedValue.resourceId);
color = ResourcesCompat23.getColor(context.getResources(), typedValue.resourceId);
} catch (Exception e) {
color = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1278,11 +1278,10 @@ private int getRequiredRotation() {
/**
* Pythagoras distance between two points.
*/
@SuppressWarnings("deprecation")
private float distance(float x0, float x1, float y0, float y1) {
float x = x0 - x1;
float y = y0 - y1;
return android.util.FloatMath.sqrt(x * x + y * y);
return (float) Math.sqrt(x * x + y * y);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.support.v4.view.ViewCompat;
import android.view.animation.Animation;
import android.widget.ImageView;
import nya.miku.wishmaster.ui.ResourcesCompat23;

/**
* Private class created to work around issues with AnimationListeners being
Expand Down Expand Up @@ -105,7 +106,7 @@ public void onAnimationEnd() {
public void setBackgroundColor(int colorRes) {
if (getBackground() instanceof ShapeDrawable) {
final Resources res = getResources();
((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));
((ShapeDrawable) getBackground()).getPaint().setColor(ResourcesCompat23.getColor(res, colorRes));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.view.animation.Transformation;
import android.widget.AbsListView;
import android.widget.ScrollView;
import nya.miku.wishmaster.ui.ResourcesCompat23;

/**
* The SwipeRefreshLayout should be used whenever the user can refresh the
Expand Down Expand Up @@ -460,7 +461,7 @@ public void applyTransformation(float interpolatedTime, Transformation t) {
*/
public void setProgressBackgroundColor(int colorRes) {
mCircleView.setBackgroundColor(colorRes);
mProgress.setBackgroundColor(getResources().getColor(colorRes));
mProgress.setBackgroundColor(ResourcesCompat23.getColor(getResources(), colorRes));
}

/**
Expand All @@ -482,7 +483,7 @@ public void setColorSchemeResources(int... colorResIds) {
final Resources res = getResources();
int[] colorRes = new int[colorResIds.length];
for (int i = 0; i < colorResIds.length; i++) {
colorRes[i] = res.getColor(colorResIds[i]);
colorRes[i] = ResourcesCompat23.getColor(res, colorResIds[i]);
}
setColorSchemeColors(colorRes);
}
Expand Down
17 changes: 17 additions & 0 deletions src/nya/miku/wishmaster/ui/CompatibilityImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import android.content.ClipboardManager;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.net.Uri;
Expand Down Expand Up @@ -273,4 +275,19 @@ public static void setImageAlpha(ImageView imageView, int alpha) {
imageView.setImageAlpha(alpha);
}

@TargetApi(Build.VERSION_CODES.M)
public static int getColor(Resources resources, int id) {
return resources.getColor(id, null);
}

@TargetApi(Build.VERSION_CODES.M)
public static ColorStateList getColorStateList(Resources resources, int id) {
return resources.getColorStateList(id, null);
}

@TargetApi(Build.VERSION_CODES.M)
public static void setTextAppearance(TextView textView, int resId) {
textView.setTextAppearance(resId);
}

}
54 changes: 54 additions & 0 deletions src/nya/miku/wishmaster/ui/ResourcesCompat23.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Overchan Android (Meta Imageboard Client)
* Copyright (C) 2014-2015 miku-nyan <https://github.com/miku-nyan>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package nya.miku.wishmaster.ui;

import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.os.Build;
import android.widget.TextView;

public class ResourcesCompat23 {

@SuppressWarnings("deprecation")
public static int getColor(Resources resources, int id) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return resources.getColor(id);
} else {
return CompatibilityImpl.getColor(resources, id);
}
}

@SuppressWarnings("deprecation")
public static ColorStateList getColorStateList(Resources resources, int id) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return resources.getColorStateList(id);
} else {
return CompatibilityImpl.getColorStateList(resources, id);
}
}

@SuppressWarnings("deprecation")
public static void setTextAppearance(TextView textView, int resId) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
textView.setTextAppearance(textView.getContext(), resId);
} else {
CompatibilityImpl.setTextAppearance(textView, resId);
}
}
}
9 changes: 5 additions & 4 deletions src/nya/miku/wishmaster/ui/presentation/BoardFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import nya.miku.wishmaster.ui.GalleryActivity;
import nya.miku.wishmaster.ui.MainActivity;
import nya.miku.wishmaster.ui.QuickAccess;
import nya.miku.wishmaster.ui.ResourcesCompat23;
import nya.miku.wishmaster.ui.downloading.DownloadingService;
import nya.miku.wishmaster.ui.downloading.BackgroundThumbDownloader;
import nya.miku.wishmaster.ui.posting.PostFormActivity;
Expand Down Expand Up @@ -3303,7 +3304,7 @@ public void run() {

final Button btnToSelecting = new Button(activity);
btnToSelecting.setText(R.string.grid_gallery_select);
btnToSelecting.setTextAppearance(activity, android.R.style.TextAppearance_Small);
ResourcesCompat23.setTextAppearance(btnToSelecting, android.R.style.TextAppearance_Small);
btnToSelecting.setSingleLine();
btnToSelecting.setVisibility(View.VISIBLE);
btnToSelecting.setLayoutParams(
Expand All @@ -3315,17 +3316,17 @@ public void run() {
Button btnDownload = new Button(activity);
btnDownload.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.25f));
btnDownload.setText(R.string.grid_gallery_download);
btnDownload.setTextAppearance(activity, android.R.style.TextAppearance_Small);
ResourcesCompat23.setTextAppearance(btnDownload, android.R.style.TextAppearance_Small);
btnDownload.setSingleLine();
Button btnSelectAll = new Button(activity);
btnSelectAll.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.75f));
btnSelectAll.setText(android.R.string.selectAll);
btnSelectAll.setTextAppearance(activity, android.R.style.TextAppearance_Small);
ResourcesCompat23.setTextAppearance(btnSelectAll, android.R.style.TextAppearance_Small);
btnSelectAll.setSingleLine();
Button btnCancel = new Button(activity);
btnCancel.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3f));
btnCancel.setText(android.R.string.cancel);
btnCancel.setTextAppearance(activity, android.R.style.TextAppearance_Small);
ResourcesCompat23.setTextAppearance(btnCancel, android.R.style.TextAppearance_Small);
btnCancel.setSingleLine();
layoutSelectingButtons.addView(btnDownload);
layoutSelectingButtons.addView(btnSelectAll);
Expand Down
3 changes: 2 additions & 1 deletion src/nya/miku/wishmaster/ui/presentation/HtmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package nya.miku.wishmaster.ui.presentation;

import android.graphics.Color;
import nya.miku.wishmaster.ui.ResourcesCompat23;
import nya.miku.wishmaster.ui.presentation.ClickableURLSpan.URLSpanClickListener;
import nya.miku.wishmaster.ui.presentation.ThemeUtils.ThemeColors;

Expand Down Expand Up @@ -537,7 +538,7 @@ private static void endFont(SpannableStringBuilder text) {
String name = f.mColor.substring(1);
int colorRes = res.getIdentifier(name, "color", "android");
if (colorRes != 0) {
ColorStateList colors = res.getColorStateList(colorRes);
ColorStateList colors = ResourcesCompat23.getColorStateList(res, colorRes);
text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
} else {
Expand Down

0 comments on commit 3eb8b6d

Please sign in to comment.