Sunteți pe pagina 1din 19

Pocket diary application have many coding parts such as java, xml, drawable.

xml, gradleview, mainifest,


etc. All the parts of android is important to take output if there is any single error in every part then
gradle will not start and the program will terminate automatically. There is part of storing data which is
shared preference it is the storing database which is very useful to save users data and information with
secure password system.

Here are there major coding part of this project

 Java
 XML
 Drawable XML
 Mainifest XML

JAVA:-
AddCustomItem.java:-

public class AddCustomItem extends Activity implements OnClickListener


{
Button saveCustomItem;
private Long mSubFolderId,mItemID;
Integer intOld;
private PocketDbAdapter mDbHelper;
private EditText CustomItem;
String mItemName,mItemDataType,mItemType;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
mDbHelper = new PocketDbAdapter(this);
mDbHelper.open();
Bundle extras = getIntent().getExtras();
mSubFolderId = savedInstanceState!=null ?
savedInstanceState.getLong(information.SubFolderID): null;
if(mSubFolderId == null)
{
mSubFolderId = extras !=null? extras.getLong(information.SubFolderID) : null;

}
intOld = savedInstanceState!=null ? savedInstanceState.getInt(subfolder.intOld): null;
if(intOld == null)
{
intOld = extras !=null? extras.getInt(subfolder.intOld) : 0;

}
setContentView(R.layout.custom_item_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
final TextView centertext = (TextView) findViewById(R.id.center_text);
centertext.setText("Add Custom Item");
CustomItem = (EditText)findViewById(R.id.CustomItem);
final Spinner s1 = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.CustomItemType, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id)
{
String selectedItemString = (String)s1.getSelectedItem();

mItemType = selectedItemString;

if(mItemType.equals("Numeric"))
{
mItemDataType = information.ITEM_NUMERIC;
}
else if(mItemType.equals("Text"))
{
mItemDataType = information.ITEM_TEXT;
}
else if(mItemType.equals("Text Box"))
{
mItemDataType = information.ITEM_MULTITEXT;
}
else if(mItemType.equals("Date Format"))
{
mItemDataType = information.ITEM_DATE;
}
else
{
mItemDataType = information.ITEM_TEXT;
}

public void onNothingSelected(AdapterView<?> arg0)


{

}
});
saveCustomItem = (Button)findViewById(R.id.saveCustomItem);
saveCustomItem.setOnClickListener(this);
}

@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putLong(information.SubFolderID, mSubFolderId);
outState.putInt(subfolder.intOld, intOld);
}

@Override
public void onClick(View v)
{
mItemName = CustomItem.getText().toString();
if(v.getId()==R.id.saveCustomItem)
{
if(mItemName.length()>0)
{

if(mItemID==null)
{
long id;
if(intOld==1)
{
id = mDbHelper.CreateInformation(mItemDataType, mItemName, mSubFolderId);
}
else
{
id = mDbHelper.CreateInformation(mItemDataType, mItemName, 0);
}

if(id > 0)
{
mItemID = id;

}
}
Intent intent = new Intent();
intent.putExtra(information.SubFolderID , mSubFolderId);
intent.putExtra("mItemID", mItemID);
setResult(RESULT_OK, intent);
finish();
return;
}
else
{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Item Name");
alertDialog.setMessage("Please enter Item Name.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
return;
}
});
alertDialog.show();
}

}
}

Pocketdiary.java:-

public class aPocketDiary extends Activity implements OnTouchListener{


private static final int ACTIVITY_START=0;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
RelativeLayout r = (RelativeLayout)findViewById(R.id.pocketwelcome);
startnew();
r.setOnTouchListener(this);

}
public boolean onTouch (View v, MotionEvent event )
{
startnew();
return true;
}

public void startnew()


{
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
try
{
Intent loginIntent;
SharedPreferences passwdfile =
getSharedPreferences(LoginView.PASSWORD_PREF_KEY,0);
String correctMd5 =
passwdfile.getString(LoginView.PASSWORD_PREF_KEY,null);

if(correctMd5 != null)
{
//Bundle bundle= new Bundle();
//bundle.putString("correctMd5", correctMd5);
loginIntent= new Intent(aPocketDiary.this,Authentication.class);
//loginIntent.putExtras(bundle);

}
else
{
loginIntent= new Intent(aPocketDiary.this,LoginView.class);

}
startActivityForResult(loginIntent,ACTIVITY_START);

}
catch (Throwable er)
{
Toast.makeText(aPocketDiary.this, "Error "+er.getMessage(),
Toast.LENGTH_LONG).show();

}
}
}, 3000);

}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
startnew();

Login.java:-
public class LoginView extends Activity implements
OnClickListener
{
public static final String PASSWORD_PREF_KEY = "passwd";
Button btnSavePassword;
private EditText pass1;
private EditText pass2;
private AlertDialog alertDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.setpassword);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
final TextView centertext = (TextView)
findViewById(R.id.center_text);
centertext.setText("Set Password");
pass1 = (EditText) findViewById(R.id.password);
pass2 = (EditText) findViewById(R.id.password_confirm);
btnSavePassword = (Button)findViewById(R.id.ok);
btnSavePassword.setOnClickListener(this);

}
public void onClick(View v)
{
String p1 = pass1.getText().toString();
String p2 = pass2.getText().toString();
if (p1.equals(p2))
{

if (p1.length() >= 6 || p2.length() >= 6)


{
Editor passwdfile =
getSharedPreferences(LoginView.PASSWORD_PREF_KEY, 0).edit();
String md5hash = getMd5Hash(p1);
passwdfile.putString(LoginView.PASSWORD_PREF_KEY,
md5hash);
passwdfile.commit();
alertDialog = new
AlertDialog.Builder(this).create();
//alertDialog.setTitle("Passwords must be at
least 6 characters")
alertDialog.setMessage("If you forgot password,
there is no way to get back.");
alertDialog.setButton("OK", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface
dialog, int which)
{
Intent categoryIntent= new
Intent(LoginView.this,ItemList.class);
startActivity(categoryIntent);
finish();
return;
}
});

}
else
{
if(p1.length()==0)
{
alertDialog = new
AlertDialog.Builder(this).create();
alertDialog.setTitle("Password");
alertDialog.setMessage("Please enter
password.");
alertDialog.setButton("OK", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface
dialog, int which)
{
return;
}
});
}
else
{
alertDialog = new
AlertDialog.Builder(this).create();
alertDialog.setTitle("Password");
alertDialog.setMessage("Passwords must be at
least 6 characters.");
alertDialog.setButton("OK", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface
dialog, int which) {
return;
}
});
}

}
else
{
pass1.setText("");
pass2.setText("");
alertDialog = new AlertDialog.Builder(this).create();
//.setTitle("Passwords do not match")
alertDialog.setMessage("Passwords do not match");
alertDialog.setButton("OK", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
which)
{
return;
}
});

alertDialog.show();

}
public static String getMd5Hash(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger number = new BigInteger(1,messageDigest);
String md5 = number.toString(16);

while (md5.length() < 32)


md5 = "0" + md5;

return md5;
} catch(NoSuchAlgorithmException e) {
Log.e("MD5", e.getMessage());
return null;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent msg)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
Intent intent = new Intent();
setResult(RESULT_OK,intent);
finish();

}
return true;
}

ItemList.java:-

public class ItemList extends Activity implements


OnClickListener
{
public static final int HELP_ID = Menu.FIRST;
public static final int ADD_CATEGORY = Menu.FIRST + 1;
private static final int ACTIVITY_CREATE=0;
private static final int ACTIVITY_CREATE_SUBFOLDER=1;
private ListView lv;
private PocketDbAdapter mDbHelper;
private Cursor folderCursor;
Button menu_help;
Button btnAddNewFolder;
/** Called when the activity is first created. */
@Override

protected void onCreate(Bundle savedInstanceState)


{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
setContentView(R.layout.folder_list_main);
lv = (ListView)findViewById(R.id.lvfoldermain);
mDbHelper = new PocketDbAdapter(this);
mDbHelper.open();
fillData();
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
final TextView centertext = (TextView)
findViewById(R.id.center_text);
centertext.setText("Pocket Diary");
menu_help = (Button)findViewById(R.id.menu_help);
btnAddNewFolder=
(Button)findViewById(R.id.btnAddNewFolder);
menu_help.setOnClickListener(this);
btnAddNewFolder.setOnClickListener(this);
}
public void onClick(View v)
{

if(v.getId()==R.id.menu_help)
{
Intent changePassIntent= new Intent(this,Help.class);
startActivity(changePassIntent);
}
else if(v.getId()==R.id.btnAddNewFolder)
{
Intent folderEditorIntent= new
Intent(this,FolderEditor.class);

startActivityForResult(folderEditorIntent,ACTIVITY_CREATE);
}
}
private void fillData()
{
try
{
folderCursor = mDbHelper.FetchAllFolders();
startManagingCursor(folderCursor);
lv.setAdapter(new EfficientAdapter(this,folderCursor));
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View
v, int position, long id)
{
Intent SubFolderListIntent = new
Intent(ItemList.this, SubItemList.class);
SubFolderListIntent.putExtra(subfolder.FolderID,
id);

startActivityForResult(SubFolderListIntent,ACTIVITY_CREATE_SUBFO
LDER);
}
});
}
catch (Throwable er)
{
Toast.makeText(this, "Error "+er.getMessage(),
Toast.LENGTH_LONG).show();

}
private class EfficientAdapter extends CursorAdapter
{
private final LayoutInflater mInflater;
public EfficientAdapter(Context context, Cursor cursor)
{
super(context,cursor,true);
mInflater = LayoutInflater.from(context);
}

@Override
public void bindView(View view, Context context, Cursor
cursor)
{
int resID =
getResources().getIdentifier(cursor.getString(cursor.getColumnIn
dex(folder.FolderImage)), "drawable",
"com.softwaredepotonline.iPocketDiary");
ImageView s = (ImageView)
view.findViewById(R.id.FolderIcon);
s.setImageResource(resID);
TextView t = (TextView)
view.findViewById(R.id.sFolderName);

t.setText(cursor.getString(cursor.getColumnIndex(folder.FolderNa
me)));

@Override
public View newView(Context context, Cursor cursor,
ViewGroup parent)
{
// TODO Auto-generated method stub
final View view =
mInflater.inflate(R.layout.folderlist_item, parent, false);

return view;

@Override
protected void onActivityResult(int requestCode, int
resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}

XML:-
Authlayout.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:background="@drawable/password"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="20dip"
>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="40dip">
<TextView android:layout_height="wrap_content"
android:text="@string/enter_password"
android:id="@+id/label"
android:layout_width="150px"
style="@style/textview_style"/>
<EditText android:id="@+id/password"
android:maxLines="1"
android:singleLine="true"
android:layout_height="wrap_content"
android:password="true"
android:inputType="textPassword"
android:layout_marginTop="5dip"
android:background="@android:drawable/editbox_background"
android:layout_width="160dip"
android:layout_below="@id/label"
/>
<Button
android:id="@+id/ok"
android:layout_width="150dip"
android:text="@string/button_ok"
android:layout_gravity="left"
android:layout_marginTop="10dip"
android:layout_below="@id/password"
android:layout_height="40dip" android:soundEffectsEnabled="true"/>
<Button android:id="@+id/btnChangePassword"
style="@style/textview_btnstyle"
android:layout_marginTop="10dip"
android:layout_marginLeft="5dip"
android:text="@string/button_ChangePassword"
android:background="@drawable/textviewbutton"
android:layout_width="140dip"
android:layout_height="35dip"
android:layout_below="@+id/ok"/>
</RelativeLayout>
</LinearLayout>

Setpassword.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:background="@drawable/password"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="20dip"
>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="40dip">
<TextView android:layout_height="wrap_content"
android:text="@string/enter_password"
android:id="@+id/label"
android:layout_width="150px"
style="@style/textview_style"/>
<EditText android:id="@+id/password"
android:maxLines="1"
android:singleLine="true"
android:layout_height="wrap_content"
android:password="true"
android:inputType="textPassword"
android:layout_marginTop="5dip"
android:background="@android:drawable/editbox_background"
android:layout_width="160dip"
android:layout_below="@id/label"
/>
<Button
android:id="@+id/ok"
android:layout_width="150dip"
android:text="@string/button_ok"
android:layout_gravity="left"
android:layout_marginTop="10dip"
android:layout_below="@id/password"
android:layout_height="40dip" android:soundEffectsEnabled="true"/>
<Button android:id="@+id/btnChangePassword"
style="@style/textview_btnstyle"
android:layout_marginTop="10dip"
android:layout_marginLeft="5dip"
android:text="@string/button_ChangePassword"
android:background="@drawable/textviewbutton"
android:layout_width="140dip"
android:layout_height="35dip"
android:layout_below="@+id/ok"/>
</RelativeLayout>
</LinearLayout>

Categorylist.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip">

<ImageView android:id="@+id/FolderIcon"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content" />

<TextView android:id="@+id/sFolderName"
android:layout_gravity="center_vertical"
android:paddingLeft="10dip"
android:layout_width="0dip"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<ImageView android:id="@+id/ArrowIcon"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:background="@drawable/forward_32"/>

</LinearLayout>

Infomain.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/help"
android:layout_height="fill_parent"
>

<LinearLayout
android:background="@drawable/border"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<ImageView android:id="@+id/subFolderImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/bank"
/>
<TextView
android:id="@+id/subFolderName"
android:layout_gravity="center_vertical"
android:paddingLeft="10dip"
android:layout_width="0dip"
android:layout_weight="1.0"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
/>
<Button android:id="@+id/btnEditSubFolder"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:background="@drawable/btn_expand" />
</LinearLayout>
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_marginTop="15dp"
android:paddingLeft="20dip"
android:layout_weight="1.0"
android:layout_height="fill_parent"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/btnAddNewItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/ic_menu_add"
android:soundEffectsEnabled="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="50dip"/>

<Button
android:id="@+id/btnDeleteSubFolder"
android:background="@android:drawable/ic_menu_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:soundEffectsEnabled="true"
android:layout_marginRight="50dip"/>

</RelativeLayout>

</LinearLayout>

DRAWABLE XML:-

Border.xml:-

<?xml version="1.0" encoding="utf-8"?>


<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="#ee777777" />
<solid android:color="#ee444444" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
<corners android:radius="15dp" />
</shape>
Buttonstyle.xml

<?xml version="1.0" encoding="utf-8"?>


<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<padding android:left="5dp" android:top="5dp"
android:right="5dp" android:bottom="5dp" />
<corners android:radius="10dp" />
</shape>

Checkmark.xml:-

<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/ic_text_dot_c_invert" />
<item android:drawable="@drawable/ic_text_dot_c" />

</selector>
Textviewbutton.xml:-

<?xml version="1.0" encoding="utf-8"?>


<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#ffffff" />
<solid />
<corners android:radius="5dp" />
</shape>

AndroidManifest.xml:-

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.softwaredepotonline.iPocketDiary"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true" android:resizeable="true"/>
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".aPocketDiary"
android:screenOrientation="portrait" android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".Help" android:screenOrientation="portrait"


android:clearTaskOnLaunch="true"></activity>
<activity android:name=".LoginView" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".Authentication" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".HelpPassword" android:label="Password Help"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".ChangePasswordView"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".ItemList" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".SubItemList" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".FolderEditor" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".SubFolderEditor" android:label="Create Subfolder"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".Information" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true" ></activity>
<activity android:name=".AddNewItem" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>
<activity android:name=".AddCustomItem" android:screenOrientation="portrait"
android:clearTaskOnLaunch="true"></activity>

</application>
<uses-sdk android:minSdkVersion="4" android:maxSdkVersion="7"/>

</manifest>

S-ar putea să vă placă și