Last active
July 26, 2016 06:14
-
-
Save dassoubarna/9816883aec79c565293b90b11818b91c to your computer and use it in GitHub Desktop.
Android Web App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout 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" | |
android:orientation="vertical" | |
tools:context="in.gogols.sweetstore.MainActivity" > | |
<ProgressBar | |
android:id="@+id/progressBar1" | |
style="?android:attr/progressBarStyleSmall" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:indeterminate="false" | |
android:layout_gravity="center" /> | |
<WebView | |
android:id="@+id/activity_main_webview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout 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" | |
android:background="@drawable/vert_loading" | |
tools:context=".Splash" > | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="in.gogols.sweetstore" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
<uses-permission android:name="android.permission.VIBRATE" /> | |
<!-- <badges> --> | |
<!--for Samsung--> | |
<uses-permission android:name="com.sec.android.provider.badge.permission.READ"/> | |
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/> | |
<!--for htc--> | |
<uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS"/> | |
<uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT"/> | |
<!--for sony--> | |
<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE"/> | |
<!--for apex--> | |
<uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT"/> | |
<!--for solid--> | |
<uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE"/> | |
<!-- </badges> --> | |
<supports-screens android:anyDensity="true" /> | |
<!--library--> | |
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> | |
<!-- Keeps the processor from sleeping when a message is received. --> | |
<uses-permission android:name="android.permission.WAKE_LOCK" /> | |
<!-- | |
Creates a custom permission so only this app can receive its messages. | |
NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE, | |
where PACKAGE is the application's package name. | |
--> | |
<permission | |
android:name="com.pushwoosh.test.tags.sample.app.permission.C2D_MESSAGE" | |
android:protectionLevel="signature" /> | |
<uses-permission android:name="com.pushwoosh.test.tags.sample.app.permission.C2D_MESSAGE" /> | |
<!-- This app has permission to register and receive data message. --> | |
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> | |
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> | |
<!-- GCM requires Android SDK version 2.2 (API level 8) or above. --> | |
<!-- The targetSdkVersion is optional, but it's always a good practice | |
to target higher versions. --> | |
<uses-sdk | |
android:minSdkVersion="19" | |
android:targetSdkVersion="19" /> | |
<application | |
android:allowBackup="true" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<meta-data | |
android:name="PW_APPID" | |
android:value="9B5D3-42299" /> | |
<meta-data | |
android:name="PW_PROJECT_ID" | |
android:value="A803427181962" /> | |
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> | |
<receiver android:name="com.pushwoosh.local.BootReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED" android:enabled="true"> | |
<intent-filter> | |
<action android:name="android.intent.action.BOOT_COMPLETED" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
</intent-filter> | |
</receiver> | |
<activity | |
android:name=".MainActivity" | |
android:label="@string/app_name" | |
android:screenOrientation="portrait" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
</intent-filter> | |
<intent-filter> | |
<action android:name="com.pushwoosh.test.tags.sample.app.MESSAGE" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
</intent-filter> | |
</activity> | |
<activity | |
android:name=".Splash" | |
android:label="@string/app_name" | |
android:screenOrientation="portrait" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<receiver | |
android:name="com.google.android.gms.gcm.GcmReceiver" | |
android:exported="true" | |
android:permission="com.google.android.c2dm.permission.SEND" > | |
<intent-filter> | |
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> | |
<category android:name="com.pushwoosh.test.tags.sample.app" /> | |
</intent-filter> | |
</receiver> | |
<receiver | |
android:name="com.pushwoosh.test.tags.sample.app.SilentPushReceiver" | |
android:permission=".permission.C2D_MESSAGE" > | |
<intent-filter> | |
<action android:name="com.pushwoosh.test.tags.sample.app.action.SILENT_PUSH_RECEIVE" /> | |
</intent-filter> | |
</receiver> | |
<service | |
android:name="com.pushwoosh.GCMListenerService" | |
android:exported="false"> | |
<intent-filter> | |
<action android:name="com.google.android.c2dm.intent.RECEIVE"/> | |
</intent-filter> | |
</service> | |
<service | |
android:name="com.pushwoosh.GCMInstanceIDListenerService" | |
android:exported="false"> | |
<intent-filter> | |
<action android:name="com.google.android.gms.iid.InstanceID"/> | |
</intent-filter> | |
</service> | |
<service | |
android:name="com.pushwoosh.GCMRegistrationService" | |
android:exported="false"> | |
</service> | |
</application> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<menu xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
tools:context="in.gogols.sweetstore.MainActivity" > | |
<item | |
android:id="@+id/share" | |
android:title="@string/share" | |
android:showAsAction="ifRoom" | |
android:actionProviderClass="android.widget.ShareActionProvider"/> | |
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package in.gogols.sweetstore; | |
import com.pushwoosh.BasePushMessageReceiver; | |
import com.pushwoosh.BaseRegistrationReceiver; | |
import com.pushwoosh.PushManager; | |
import android.widget.Toast; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.Menu; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.IntentFilter; | |
import android.view.View; | |
import android.view.Window; | |
import android.webkit.WebSettings; | |
import android.webkit.WebView; | |
import android.widget.ShareActionProvider; | |
import android.view.WindowManager; | |
public class MainActivity extends Activity { | |
private WebView mWebView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//No title bar is set for the activity | |
requestWindowFeature(Window.FEATURE_NO_TITLE); | |
//Full screen is set for the Window | |
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | |
WindowManager.LayoutParams.FLAG_FULLSCREEN); | |
setContentView(R.layout.activity_main); | |
mWebView = (WebView) findViewById(R.id.activity_main_webview); | |
WebSettings webSettings = mWebView.getSettings(); | |
webSettings.setJavaScriptEnabled(true); | |
mWebView.loadUrl("http://gogols.in/"); | |
mWebView.setWebViewClient(new in.gogols.sweetstore.MyAppWebViewClient(){ | |
@Override | |
public void onPageFinished(WebView view, String url) { | |
//hide loading image | |
findViewById(R.id.progressBar1).setVisibility(View.GONE); | |
//show webview | |
findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE); | |
}}); | |
//Register receivers for push notifications | |
registerReceivers(); | |
//Create and start push manager | |
PushManager pushManager = PushManager.getInstance(this); | |
//Start push manager, this will count app open for Pushwoosh stats as well | |
try { | |
pushManager.onStartup(this); | |
} | |
catch(Exception e) | |
{ | |
Log.e("Pushwoosh", e.getLocalizedMessage()); | |
//push notifications are not available or AndroidManifest.xml is not configured properly | |
} | |
//Register for push! | |
pushManager.registerForPushNotifications(); | |
checkMessage(getIntent()); | |
} | |
@Override | |
protected void onNewIntent(Intent intent) | |
{ | |
super.onNewIntent(intent); | |
setIntent(intent); | |
checkMessage(intent); | |
} | |
//Registration receiver | |
BroadcastReceiver mBroadcastReceiver = new BaseRegistrationReceiver() | |
{ | |
@Override | |
public void onRegisterActionReceive(Context context, Intent intent) | |
{ | |
checkMessage(intent); | |
} | |
}; | |
//Push message receiver | |
private BroadcastReceiver mReceiver = new BasePushMessageReceiver() | |
{ | |
@Override | |
protected void onMessageReceive(Intent intent) | |
{ | |
//JSON_DATA_KEY contains JSON payload of push notification. | |
showMessage("push message is " + intent.getExtras().getString(JSON_DATA_KEY)); | |
} | |
}; | |
//Registration of the receivers | |
public void registerReceivers() | |
{ | |
IntentFilter intentFilter = new IntentFilter(getPackageName() + ".action.PUSH_MESSAGE_RECEIVE"); | |
registerReceiver(mReceiver, intentFilter, getPackageName() +".permission.C2D_MESSAGE", null); | |
registerReceiver(mBroadcastReceiver, new IntentFilter(getPackageName() + "." + PushManager.REGISTER_BROAD_CAST_ACTION)); | |
} | |
public void unregisterReceivers() | |
{ | |
//Unregister receivers on pause | |
try | |
{ | |
unregisterReceiver(mReceiver); | |
} | |
catch (Exception e) | |
{ | |
// pass. | |
} | |
try | |
{ | |
unregisterReceiver(mBroadcastReceiver); | |
} | |
catch (Exception e) | |
{ | |
//pass through | |
} | |
} | |
@Override | |
public void onResume() | |
{ | |
super.onResume(); | |
//Re-register receivers on resume | |
registerReceivers(); | |
} | |
@Override | |
public void onPause() | |
{ | |
super.onPause(); | |
//Unregister receivers on pause | |
unregisterReceivers(); | |
} | |
private void checkMessage(Intent intent) | |
{ | |
if (null != intent) | |
{ | |
if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT)) | |
{ | |
showMessage("push message is " + intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT)); | |
} | |
else if (intent.hasExtra(PushManager.REGISTER_EVENT)) | |
{ | |
showMessage("register"); | |
} | |
else if (intent.hasExtra(PushManager.UNREGISTER_EVENT)) | |
{ | |
showMessage("unregister"); | |
} | |
else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT)) | |
{ | |
showMessage("register error"); | |
} | |
else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT)) | |
{ | |
showMessage("unregister error"); | |
} | |
resetIntentValues(); | |
} | |
} | |
/** | |
* Will check main Activity intent and if it contains any PushWoosh data, will clear it | |
*/ | |
private void resetIntentValues() | |
{ | |
Intent mainAppIntent = getIntent(); | |
if (mainAppIntent.hasExtra(PushManager.PUSH_RECEIVE_EVENT)) | |
{ | |
mainAppIntent.removeExtra(PushManager.PUSH_RECEIVE_EVENT); | |
} | |
else if (mainAppIntent.hasExtra(PushManager.REGISTER_EVENT)) | |
{ | |
mainAppIntent.removeExtra(PushManager.REGISTER_EVENT); | |
} | |
else if (mainAppIntent.hasExtra(PushManager.UNREGISTER_EVENT)) | |
{ | |
mainAppIntent.removeExtra(PushManager.UNREGISTER_EVENT); | |
} | |
else if (mainAppIntent.hasExtra(PushManager.REGISTER_ERROR_EVENT)) | |
{ | |
mainAppIntent.removeExtra(PushManager.REGISTER_ERROR_EVENT); | |
} | |
else if (mainAppIntent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT)) | |
{ | |
mainAppIntent.removeExtra(PushManager.UNREGISTER_ERROR_EVENT); | |
} | |
setIntent(mainAppIntent); | |
} | |
private void showMessage(String message) | |
{ | |
Toast.makeText(this, message, Toast.LENGTH_LONG).show(); | |
} | |
private ShareActionProvider mShareActionProvider; | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
/** Inflating the current activity's menu with res/menu/items.xml */ | |
getMenuInflater().inflate(R.menu.main, menu); | |
/** Getting the actionprovider associated with the menu item whose id is share */ | |
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share).getActionProvider(); | |
/** Setting a share intent */ | |
mShareActionProvider.setShareIntent(getDefaultShareIntent()); | |
return super.onCreateOptionsMenu(menu); | |
} | |
private Intent getDefaultShareIntent(){ | |
Intent intent = new Intent(Intent.ACTION_SEND); | |
intent.setType("text/plain"); | |
intent.putExtra(Intent.EXTRA_SUBJECT, "Your Online Sweet Store"); | |
intent.putExtra(Intent.EXTRA_TEXT," Vist www.gogols.in "); | |
return intent; | |
} | |
@Override | |
public void onBackPressed() { | |
if(mWebView.canGoBack()) { | |
mWebView.goBack(); | |
} else { | |
super.onBackPressed(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package in.gogols.sweetstore; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.webkit.WebView; | |
import android.webkit.WebViewClient; | |
public class MyAppWebViewClient extends WebViewClient { | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
if(Uri.parse(url).getHost().endsWith("gogols.in")) { | |
return false; | |
} | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
view.getContext().startActivity(intent); | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package in.gogols.sweetstore; | |
import android.annotation.SuppressLint; | |
import android.annotation.TargetApi; | |
import android.app.ActionBar; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Build; | |
import android.os.Bundle; | |
@SuppressLint("NewApi") | |
public class Splash extends Activity { | |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) | |
@SuppressLint("NewApi") | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_splash); | |
ActionBar actionBar = getActionBar(); | |
actionBar.hide(); | |
Thread t =new Thread(){ | |
public void run(){ | |
try{ | |
sleep(10000); | |
}catch(InterruptedException e){ | |
e.printStackTrace(); | |
}finally{ | |
Intent i =new Intent(Splash.this,MainActivity.class); | |
startActivity(i); | |
} | |
} | |
}; | |
t.start(); | |
} | |
@Override | |
public void onPause(){ | |
super.onPause(); | |
finish(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="app_name">Gogols</string> | |
<string name="hello_world">Hello world!</string> | |
<string name="share">Share</string> | |
<string name="action_settings">Settings</string> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment