Skip to content

Commit

Permalink
add swipe back
Browse files Browse the repository at this point in the history
  • Loading branch information
Tneciv committed May 18, 2016
1 parent bd9231b commit 74b1f08
Show file tree
Hide file tree
Showing 32 changed files with 622 additions and 71 deletions.
17 changes: 9 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile files('libs/Bughd_android_sdk_v1.3.7.jar')
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.android.support:palette-v7:23.3.0'
compile 'com.google.code.gson:gson:2.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
provided 'de.greenrobot:eventbus-annotation-processor:3.0.0-beta1'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:palette-v7:23.4.0'
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'de.greenrobot:eventbus:3.0.0-beta1'
provided 'de.greenrobot:eventbus-annotation-processor:3.0.0-beta1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton:disklrucache:2.0.2'
compile 'com.github.paolorotolo:appintro:3.4.0'
Expand All @@ -65,4 +65,5 @@ dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'net.yslibrary.licenseadapter:licenseadapter:1.2.1'
compile 'com.google.guava:guava-io:r03'
compile 'com.jude:swipebackhelper:3.0.4'
}
36 changes: 22 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tneciv.zhihudaily">
package="com.tneciv.zhihudaily">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:name=".MyApplication"
Expand All @@ -22,9 +22,9 @@
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
Expand All @@ -34,16 +34,16 @@
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.tneciv.zhihudaily.home.view.MainActivity" />
android:value="com.tneciv.zhihudaily.home.view.MainActivity"/>
</activity>
<activity
android:name=".history.view.HistoryActivity"
android:label="@string/HistoryDaily"
android:theme="@style/AppTheme.NoActionBar" />
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name=".theme.view.ThemeActivity"
android:label="@string/allSections"
android:theme="@style/AppTheme.NoActionBar" />
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name=".about.AboutActivity"
android:label="Welcome"
Expand All @@ -57,13 +57,21 @@
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.tneciv.zhihudaily.home.view.MainActivity" />
android:value="com.tneciv.zhihudaily.home.view.MainActivity"/>
</activity>

<meta-data
android:name="BUG_HD_SDK_GENERAL_KEY"
android:value="f6ca063d703f8e69a7a6f501de3373fc" />
android:value="f6ca063d703f8e69a7a6f501de3373fc"/>

<activity
android:name=".setting.view.SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".home.view.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.tneciv.zhihudaily.home.view.MainActivity"/>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tneciv.zhihudaily.about;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -25,6 +26,9 @@ public void init(@Nullable Bundle savedInstanceState) {

setSkipText("忽略");
setDoneText("开始");

askForPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
askForPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, 2);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
Expand All @@ -21,6 +22,7 @@
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.google.gson.Gson;
import com.jude.swipbackhelper.SwipeBackHelper;
import com.squareup.leakcanary.RefWatcher;
import com.squareup.picasso.Picasso;
import com.tneciv.zhihudaily.MyApplication;
Expand Down Expand Up @@ -64,6 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
ButterKnife.bind(this);
SwipeBackHelper.onCreate(this);
EventBus.getDefault().register(this);
SharedPreferences preferences = getSharedPreferences("config", Context.MODE_PRIVATE);
noImagesMode = preferences.getBoolean("noImagesMode", false);
Expand All @@ -84,11 +87,18 @@ protected void onCreate(Bundle savedInstanceState) {
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
SwipeBackHelper.onDestroy(this);
ButterKnife.unbind(this);
RefWatcher watcher = MyApplication.getRefWatcher(this);
watcher.watch(this);
}

@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
SwipeBackHelper.onPostCreate(this);
}

private void initView() {

setSupportActionBar(toolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,16 @@ public void onBackPressed() {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// getMenuInflater().inflate(R.menu.main, menu);
// getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

// if (id == R.id.action_nightMode) {
// }
// if (id == R.id.action_nightMode) {
// }

return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ private void askForPermission() {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
}
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE},
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_WRITE_EXT);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.tneciv.zhihudaily.setting.view;

import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
* to be used with AppCompat.
*/
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {

private AppCompatDelegate mDelegate;

@Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}

private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}

public ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}

public void setSupportActionBar(@Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}

@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}

@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}

@Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}

@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}

@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().addContentView(view, params);
}

@Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}

@Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}

@Override
protected void onStop() {
super.onStop();
getDelegate().onStop();
}

@Override
protected void onDestroy() {
super.onDestroy();
getDelegate().onDestroy();
}

public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu();
}
}
Loading

0 comments on commit 74b1f08

Please sign in to comment.