Vous êtes sur la page 1sur 6

this.requestWindowFeature(Window.

FEATURE_NO_TITLE); //this we
will use for not showing action bar on loading screen of app
while splash screen do not put intent for mainactivity.java
in splash screen put
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>

In navigation bar when we want to close/open drawer pass the


relativelayout object of that binding =======
mDrawerLayout.openDrawer(drawer);
where drawer is relative object
Sending gcm when gcmIntentservice is in different package we
create a new class like-------
package com.androidhive.pushnotifications;

import android.content.Context;
import com.google.android.gcm.GCMBroadcastReceiver;
public class PushLibraryBroadcastReceiver extends GCMBroadcastReceiver
{
/**
* Gets the class name of the intent service that will handle GCM messages.
*/
@Override
protected String getGCMIntentServiceClassName(Context context) {
return "com.androidhive.pushnotifications.GCMIntentService";
}
}
Then in Manifest For Receiver do this ----->

<receiver
android:name="com.androidhive.pushnotifications.PushLibraryBroa
dcastReceiver"

To display gif image in layout use a webview====


*.xml==
<WebView
android:id="@+id/webView1"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:background="@android:color/transparent"

/>
Then in java file add these lines

gifView = (WebView) findViewById(R.id.webView1);


gifView.setBackgroundColor(0x00000000);
gifView.loadUrl("file:///android_asset/triplex.GIF");

For Centering webView


android:layout_width="fill_parent"
android:layout_height="fill_parent" //add these in layout enveloping
webview
in WebView

android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"

adding progress bar on button click

add these lines to button click listener --


progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("Checking Active Internet Connection..");
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
//reset progress bar status
progressBarStatus = 0;
//reset filesize
fileSize = 0;
new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {
// process some tasks
progressBarStatus = doSomeTasks();
// your computer is too fast, sleep 1 second
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Update the progress bar
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}
// ok, file is downloaded,
if (progressBarStatus >= 100) {
// sleep 2 seconds, so that you can see the 100%
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();

}
}.start();

For adding progress bar in Async Task


after importing app.Dialog package
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type:
prgDialog = new ProgressDialog(this);
prgDialog.setMessage("Downloading Data.Please be a Harcourtian");
prgDialog.setIndeterminate(false);
prgDialog.setMax(100);
prgDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
prgDialog.setCancelable(false);
prgDialog.show();
return prgDialog;
default:
return null;
}
}
Then in async task
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
prgDialog.dismiss();}
protected void onProgressUpdate(String... values) {
// TODO Auto-generated method stub
k+=10;
prgDialog.setProgress(k);
}

Validation

private boolean isValidEmail(String email) {


String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})
$";
Pattern pattern = Pattern.compile(EMAIL_PATTERN);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}

Then set in email edittext e2 like


if(!isValidEmail(email))
{
e2.setError("Please Enter A Valid Sequence");
return;
}

Open brower on button click


url=www.facebook.com

Intent i=new Intent(Intent.Action_view);


inc.setData(Uri.parse(url));

Open dialog in Navigation Drawer


Use in
Progressdialog pd=new Progressdialog(MainActivity.this);
Here mainactivity.this scope will be whole application not just
activity

Vous aimerez peut-être aussi