package im.anuj.lit;
import im.anuj.lit.utils.Db;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Welcome extends Activity{
String[] titles = new String[]{
"Browse Catalog","Recently Read","Search","Latest","Favorites","Feedback"
};
Integer[] images = new Integer[]{
R.drawable.home_browse,R.drawable.home_recent,R.drawable.home_search,R.drawable.home_latest,R.drawable.home_fav,R.drawable.home_msg
};
@Override
public void onCreate(Bundle icicle){
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.home);
TextView title = (TextView)findViewById(R.id.TextView01);
try{
title.setTypeface(Typeface.createFromAsset(getAssets(),"OLDENGL.TTF"));
}catch(Exception e){}
GridView gv = (GridView)findViewById(R.id.GridView01);
gv.setAdapter(new ImagesAdapter());
gv.setVerticalScrollBarEnabled(false);
gv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
switch(position){
case 0:
startActivity(new Intent(getApplicationContext(),Categories.class));
break;
case 1:
startActivity(new Intent(getApplicationContext(),Recent.class));
break;
case 2:
startActivity(new Intent(getApplicationContext(),Search.class));
break;
case 3:
startActivity(new Intent(getApplicationContext(),Latest.class));
break;
case 4:
startActivity(new Intent(getApplicationContext(),Favorites.class));
break;
case 5:
showRatingMessage();
break;
}
}
});
Db myDbHelper = new Db(getApplicationContext());
try{
myDbHelper.createDataBase();
} catch (IOException ioe) {
Toast.makeText(getApplicationContext(),"Unable to create database... exiting",Toast.LENGTH_LONG);
}
try {
myDbHelper.openDataBase();
myDbHelper.closeDb();
}catch(Exception sqle){
}
}
AlertDialog ratingDialog;
public void showRatingMessage(){
if(ratingDialog==null){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Thank you for taking time to give us your feedback regarding the app. Its your feedback that keeps us motivated and help us continue the development of the app. \n\nIf you are experiencing problems please email us so they can be solved.");
builder.setPositiveButton("Give Feedback",new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
launchMarketIntent();
}
});
builder.setNegativeButton("Contact Us",new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
launchEmailIntent();
}
});
ratingDialog = builder.create();
}
ratingDialog.show();
}
public void launchMarketIntent(){
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=im.anuj.lit"));
startActivity(Intent.createChooser(i,"Lets Go"));
}
public void launchEmailIntent(){
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("plain/text");
String[] email = {"anujtenani@gmail.com"};
i.putExtra(Intent.EXTRA_EMAIL, email);
i.putExtra(Intent.EXTRA_SUBJECT,getResources().getString(R.string.app_name));
String str = "";
i.putExtra(Intent.EXTRA_TEXT, str);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(i,"Send us a message"));
}
public class ImagesAdapter extends BaseAdapter{
@Override
public int getCount() {
return titles.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row == null){
row = getLayoutInflater().inflate(R.layout.home_gridview, parent ,false);
}
ImageView iv = (ImageView)row.findViewById(R.id.ImageView01);
iv.setImageResource(images[position]);
TextView tv = (TextView)row.findViewById(R.id.TextView01);
tv.setText(titles[position]);
return row;
}
}
}
|