Skip to content

Commit

Permalink
添加引导提示
Browse files Browse the repository at this point in the history
  • Loading branch information
kassadin committed Aug 29, 2015
1 parent adad191 commit 2a35c07
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/src/main/java/com/github/koooe/ganke/ui/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.koooe.ganke.ui;

import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand All @@ -10,7 +11,9 @@

import com.github.koooe.ganke.R;
import com.github.koooe.ganke.api.Api;
import com.github.koooe.ganke.util.ColoredSnackbar;
import com.github.koooe.ganke.util.DebugLog;
import com.github.koooe.ganke.util.Once;

import butterknife.Bind;
import butterknife.ButterKnife;
Expand All @@ -24,6 +27,7 @@ public class MainActivity extends ToolbarActivity {
ViewPager viewPager;

FragmentManager fm;
long exitTime = 0;

@Override
protected int setLayoutResId() {
Expand Down Expand Up @@ -51,6 +55,15 @@ private void init() {

tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

new Once(this).show("guide_1", new Once.OnceCallback() {
@Override
public void onOnce() {
Snackbar snackbar = Snackbar.make(viewPager, "其实全都是网页链接~", Snackbar.LENGTH_LONG);
ColoredSnackbar.info(snackbar).show();

}
});
}

@Override
Expand All @@ -60,8 +73,6 @@ public void onBackPressed() {
}
}

long exitTime = 0;

private boolean doubleClickToExit() {
if ((System.currentTimeMillis() - exitTime) > 2000) {
String applicationName = getResources().getString(
Expand All @@ -71,7 +82,7 @@ private boolean doubleClickToExit() {
exitTime = System.currentTimeMillis();
return false;
} else {
return true;
return true;
}
}

Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/com/github/koooe/ganke/util/ColoredSnackbar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.koooe.ganke.util;

import android.support.design.widget.Snackbar;
import android.view.View;

/**
* 设置snackbar颜色
*/
public class ColoredSnackbar {

private static final int red = 0xfff44336;
private static final int green = 0xff4caf50;
private static final int blue = 0xff2195f3;
private static final int orange = 0xffffc107;

private static View getSnackBarLayout(Snackbar snackbar) {
if (snackbar != null) {
return snackbar.getView();
}
return null;
}

private static Snackbar colorSnackBar(Snackbar snackbar, int colorId) {
View snackBarView = getSnackBarLayout(snackbar);
if (snackBarView != null) {
snackBarView.setBackgroundColor(colorId);
}

return snackbar;
}

public static Snackbar info(Snackbar snackbar) {
return colorSnackBar(snackbar, blue);
}

public static Snackbar warning(Snackbar snackbar) {
return colorSnackBar(snackbar, orange);
}

public static Snackbar alert(Snackbar snackbar) {
return colorSnackBar(snackbar, red);
}

public static Snackbar confirm(Snackbar snackbar) {
return colorSnackBar(snackbar, green);
}
}
37 changes: 37 additions & 0 deletions app/src/main/java/com/github/koooe/ganke/util/Once.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.koooe.ganke.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
* 很方便的once
* Created by drakeet on 8/16/15.
*/
public class Once {

SharedPreferences mSharedPreferences;
Context mContext;

public Once(Context context) {
mSharedPreferences = context.getSharedPreferences("once", Context.MODE_PRIVATE);
mContext = context;
}

public void show(String tagKey, OnceCallback callback) {
boolean isSecondTime = mSharedPreferences.getBoolean(tagKey, false);
if (!isSecondTime) {
callback.onOnce();
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(tagKey, true);
editor.apply();
}
}

public void show(int tagKeyResId, OnceCallback callback) {
show(mContext.getString(tagKeyResId), callback);
}

public interface OnceCallback {
void onOnce();
}
}

0 comments on commit 2a35c07

Please sign in to comment.