Skip to content
This repository has been archived by the owner on Nov 3, 2018. It is now read-only.

Commit

Permalink
add ask for rate
Browse files Browse the repository at this point in the history
  • Loading branch information
winsontan520 committed Jun 18, 2013
1 parent 769c7fb commit b795b51
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

public class WVersionManager implements IWVersionManager {
private static final String TAG = "WVersionManager";

private static final int MODE_CHECK_VERSION = 100;
private static final int MODE_ASK_FOR_RATE = 200;


private CustomTagHandler customTagHandler;

Expand All @@ -46,6 +50,11 @@ public class WVersionManager implements IWVersionManager {
private int reminderTimer;
private int versionCode;
private AlertDialogButtonListener listener;
private boolean mDialogCancelable = true;
private boolean mIsAskForRate = false;
private String mAskForRatePositiveLabel;
private String mAskForRateNegativeLabel;
private int mMode = 100; // default mode

public WVersionManager(Activity act){
this.activity = act;
Expand All @@ -59,6 +68,7 @@ private Drawable getDefaultAppIcon() {
}

public void checkVersion() {
mMode = MODE_CHECK_VERSION;
String versionContentUrl = getVersionContentUrl();
if(versionContentUrl == null){
Log.e(TAG, "Please set versionContentUrl first");
Expand Down Expand Up @@ -86,14 +96,25 @@ public void checkVersion() {
private void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);

builder
.setIcon(getIcon())
.setTitle(getTitle())
.setMessage(Html.fromHtml(getMessage(), null, getCustomTagHandler()))
.setPositiveButton(getUpdateNowLabel(), listener)
.setNeutralButton(getRemindMeLaterLabel(), listener)
.setNegativeButton(getIgnoreThisVersionLabel(), listener)
.create();
builder.setIcon(getIcon());
builder.setTitle(getTitle());
builder.setMessage(Html.fromHtml(getMessage(), null, getCustomTagHandler()));

switch (mMode) {
case MODE_CHECK_VERSION:
builder.setPositiveButton(getUpdateNowLabel(), listener);
builder.setNeutralButton(getRemindMeLaterLabel(), listener);
builder.setNegativeButton(getIgnoreThisVersionLabel(), listener);
break;
case MODE_ASK_FOR_RATE:
builder.setPositiveButton(getAskForRatePositiveLabel(), listener);
builder.setNegativeButton(getAskForRateNegativeLabel(), listener);
break;
default:
return;
}

builder.setCancelable(isDialogCancelable());


AlertDialog dialog = builder.create();
Expand Down Expand Up @@ -179,15 +200,34 @@ public void setMessage(String message) {
*/
@Override
public String getMessage() {
return message != null? message : "What's new in this version";
String defaultMessage = null;
switch(mMode){
case MODE_CHECK_VERSION:
defaultMessage = "What's new in this version";
break;
case MODE_ASK_FOR_RATE:
defaultMessage = "Please rate us!";
break;
}

return message != null? message : defaultMessage;
}

/* (non-Javadoc)
* @see com.winsontan520.wversionmanagertest.IWVersionManager#getTitle()
*/
@Override
public String getTitle() {
return title != null? title : "New Update Available";
String defaultTitle = null;
switch(mMode){
case MODE_CHECK_VERSION:
defaultTitle = "New Update Available";
break;
case MODE_ASK_FOR_RATE:
defaultTitle = "Rate this app";
break;
}
return title != null? title : defaultTitle;
}

/* (non-Javadoc)
Expand Down Expand Up @@ -427,6 +467,34 @@ public CustomTagHandler getCustomTagHandler() {
public void setCustomTagHandler(CustomTagHandler customTagHandler) {
this.customTagHandler = customTagHandler;
}

public boolean isDialogCancelable() {
return mDialogCancelable;
}

public void setDialogCancelable(boolean dialogCancelable) {
mDialogCancelable = dialogCancelable;
}

public void askForRate(){
mMode = MODE_ASK_FOR_RATE;
showDialog();
}

public String getAskForRatePositiveLabel() {
return mAskForRatePositiveLabel == null? "OK":mAskForRatePositiveLabel;
}

public void setAskForRatePositiveLabel(String askForRatePositiveLabel) {
mAskForRatePositiveLabel = askForRatePositiveLabel;
}

public String getAskForRateNegativeLabel() {
return mAskForRateNegativeLabel == null? "Not now":mAskForRateNegativeLabel;
}

public void setAskForRateNegativeLabel(String askForRateNegativeLabel) {
mAskForRateNegativeLabel = askForRateNegativeLabel;
}

}
17 changes: 13 additions & 4 deletions sample/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wversionmanager.sample"
package="com.winsontan520.wversionmanager.sample"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.wversionmanager.sample.MainActivity"
android:name="com.winsontan520.wversionmanager.sample.ExampleListActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.winsontan520.wversionmanager.sample.CheckVersionActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.winsontan520.wversionmanager.sample.AskForRateActivity"
android:label="@string/app_name" >
</activity>
</application>

</manifest>

This file was deleted.

72 changes: 0 additions & 72 deletions sample/gen/com/example/wversionmanager/sample/R.java

This file was deleted.

Binary file removed sample/libs/wversionmanager.jar
Binary file not shown.
1 change: 1 addition & 0 deletions sample/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@

# Project target.
target=android-17
android.library.reference.1=../library
30 changes: 30 additions & 0 deletions sample/res/layout/ask_for_rate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AskForRateActivity" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >

<Button
android:id="@+id/ask_for_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ask For Rate" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/checkBox1"
android:text="Prompt dialog to ask user to rate."
android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

</ScrollView>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
tools:context=".CheckVersionActivity" >

<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.winsontan520.wversionmanager.sample;

import com.winsontan520.wversionmanager.sample.R;
import com.winsontan520.wversionmanager.library.WVersionManager;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AskForRateActivity extends Activity {
private Button askForRateButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ask_for_rate);

askForRateButton = (Button) findViewById(R.id.ask_for_rate);

askForRateButton.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
askForRate();
}
});
}

protected void askForRate() {
WVersionManager versionManager = new WVersionManager(this);
versionManager.setUpdateUrl("market://details?id=us.lovebyte");
versionManager.askForRate();

}



}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.wversionmanager.sample;
package com.winsontan520.wversionmanager.sample;

import com.winsontan520.wversionmanager.sample.R;
import com.winsontan520.wversionmanager.library.WVersionManager;

import android.os.Bundle;
Expand All @@ -8,7 +9,7 @@
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
public class CheckVersionActivity extends Activity {

// this is just a sample url to retrieve update content, the return content must follow the json format as stated in readme.md
public final static String URL_VERSION_2 = "http://bit.ly/11c7Pnb"; // this link is refer to a static text file hosted using dropbox
Expand All @@ -24,7 +25,7 @@ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.check_version);

versionContentUrl = (EditText) findViewById(R.id.versionContentUrl);
updateNowLabel = (EditText) findViewById(R.id.updateNowLabel);
Expand Down Expand Up @@ -62,6 +63,7 @@ private void checkVersion() {
versionManager.setRemindMeLaterLabel(remindMeLaterLabel.getText().toString());
versionManager.setIgnoreThisVersionLabel(ignoreThisVersionLabel.getText().toString());
versionManager.setReminderTimer(Integer.valueOf(reminderTimer.getText().toString()));

versionManager.checkVersion();
}

Expand Down
Loading

0 comments on commit b795b51

Please sign in to comment.