Skip to content

Commit 0b612e4

Browse files
committed
Refactor Codes
1 parent 6cdf0c2 commit 0b612e4

70 files changed

Lines changed: 318 additions & 331 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source-code/app/src/main/java/org/buildmlearn/toolkit/ToolkitApplication.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
/**
1212
* @brief Extended Application class
13-
*
14-
*
13+
* <p/>
14+
* <p/>
1515
* Created by Abhishek on 31-05-2015.
1616
*/
1717
public class ToolkitApplication extends Application {
@@ -20,6 +20,13 @@ public class ToolkitApplication extends Application {
2020

2121
private boolean isExternalStorageAvailable = false;
2222

23+
/**
24+
* @return Folder path
25+
* @brief Returns folder path for unzipped apks
26+
*/
27+
public static String getUnZipDir() {
28+
return dir + Constants.UNZIP;
29+
}
2330

2431
@Override
2532
public void onCreate() {
@@ -48,58 +55,49 @@ public void onCreate() {
4855
}
4956

5057
/**
51-
* @brief Returns external storage directory.
5258
* @return folder file
59+
* @brief Returns external storage directory.
5360
*/
5461
public File getDir() {
5562
return Environment.getExternalStorageDirectory();
5663
}
5764

5865
/**
59-
* @brief Returns directory for BuildmLearn toolkit manually created files.
6066
* @return folder path
67+
* @brief Returns directory for BuildmLearn toolkit manually created files.
6168
*/
6269
public String getProjectDir() {
6370
return dir + Constants.BUILD_M_LEARN_PATH;
6471

6572
}
6673

6774
/**
68-
* @brief Returns folder path for saved projects
6975
* @return Folder path
76+
* @brief Returns folder path for saved projects
7077
*/
7178
public String getSavedDir() {
7279
return dir + Constants.SAVED_DIR;
7380
}
7481

7582
/**
76-
* @brief Returns folder path for saved projects
7783
* @return Folder path
84+
* @brief Returns folder path for saved projects
7885
*/
7986
public String getDraftDir() {
8087
return dir + Constants.DRAFT_DIR;
8188
}
8289

83-
8490
/**
85-
* @brief Returns folder path for unzipped apks
8691
* @return Folder path
87-
*/
88-
public static String getUnZipDir() {
89-
return dir + Constants.UNZIP;
90-
}
91-
92-
/**
9392
* @brief Returns folder path for storing generated apks
94-
* @return Folder path
9593
*/
9694
public String getApkDir() {
9795
return dir + Constants.APK_DIR;
9896
}
9997

10098
/**
101-
* @brief Checks if external storage is present for storing data
10299
* @return true if external storage is present, else false
100+
* @brief Checks if external storage is present for storing data
103101
*/
104102
public boolean checkExternalStorage() {
105103

@@ -117,8 +115,8 @@ public boolean isExternalStorageAvailable() {
117115
}
118116

119117
/**
120-
* @brief Returns folder path for Download directory
121118
* @return Folder path
119+
* @brief Returns folder path for Download directory
122120
*/
123121
public String getDownloadDirectory() {
124122
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/AboutBuildmLearn.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ protected void onCreate(Bundle savedInstanceState) {
3636
} catch (PackageManager.NameNotFoundException e) {
3737
assert findViewById(R.id.app_version) != null;
3838
assert ((TextView) findViewById(R.id.app_version)) != null;
39-
((TextView)findViewById(R.id.app_version)).setText("Version: 1.0");
39+
((TextView) findViewById(R.id.app_version)).setText("Version: 1.0");
4040
e.printStackTrace();
4141
}
4242

4343

44-
4544
}
4645

4746
}

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/DeepLinkerActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/**
2424
* @brief Activity responsible for handling files opened from file explorer
25-
*
25+
* <p/>
2626
* This activity is started whenever users opens a .buildmlearn file from file explorer.
2727
* This activity is responsible for getting the template type from the file, and passes the template Id and
2828
* file path to Template Editor/ activity.

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/HomeActivity.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,39 @@ protected void onCreate(Bundle savedInstanceState) {
4848
R.id.navigation_drawer,
4949
(DrawerLayout) findViewById(R.id.drawer_layout));
5050
if (getIntent().hasExtra(Constants.START_FRAGMENT) && getIntent().getIntExtra(Constants.START_FRAGMENT, 0) == 3) {
51-
currentSection.setIsSelected(false);
52-
Section[] menuItem = Section.values();
53-
Section selectedMenuItem = menuItem[3];
54-
selectedMenuItem.setIsSelected(true);
55-
currentSection = selectedMenuItem;
56-
FragmentTransaction ft = getFragmentManager().beginTransaction();
57-
ft.replace(R.id.container, new SettingsFragment());
58-
ft.commit();
51+
currentSection.setIsSelected(false);
52+
Section[] menuItem = Section.values();
53+
Section selectedMenuItem = menuItem[3];
54+
selectedMenuItem.setIsSelected(true);
55+
currentSection = selectedMenuItem;
56+
FragmentTransaction ft = getFragmentManager().beginTransaction();
57+
ft.replace(R.id.container, new SettingsFragment());
58+
ft.commit();
5959
}
6060
}
61+
6162
/**
6263
* {@inheritDoc}
6364
*/
6465
@Override
6566
public void onNavigationDrawerItemSelected(int position) {
66-
if(position==-1)
67-
{
68-
if(currentSection!=null)
69-
{
70-
if(currentSection.toString().equals("OPEN_PROJECT"))
71-
{
72-
LoadProjectFragment f = (LoadProjectFragment)getFragmentManager().findFragmentByTag(currentSection.getViewName());
73-
if(f!=null)
67+
if (position == -1) {
68+
if (currentSection != null) {
69+
if (currentSection.toString().equals("OPEN_PROJECT")) {
70+
LoadProjectFragment f = (LoadProjectFragment) getFragmentManager().findFragmentByTag(currentSection.getViewName());
71+
if (f != null)
7472
f.closeSearch();
75-
}
76-
else if(currentSection.toString().equals("OPEN_APK"))
77-
{
78-
LoadApkFragment f = (LoadApkFragment)getFragmentManager().findFragmentByTag(currentSection.getViewName());
79-
if(f!=null)
73+
} else if (currentSection.toString().equals("OPEN_APK")) {
74+
LoadApkFragment f = (LoadApkFragment) getFragmentManager().findFragmentByTag(currentSection.getViewName());
75+
if (f != null)
8076
f.closeSearch();
8177
}
8278
}
83-
return ;
79+
return;
8480
}
8581
Section[] menuItem = Section.values();
8682
Section selectedMenuItem = menuItem[position];
87-
if(getSupportActionBar()!=null) {
83+
if (getSupportActionBar() != null) {
8884
getSupportActionBar().setDisplayShowHomeEnabled(true);
8985
getSupportActionBar().setDisplayShowCustomEnabled(false);
9086
}

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/SettingsLinkerActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @brief Activity responsible for changing settings from android settings menu
15-
* <p>
15+
* <p/>
1616
* This activity is started whenever users clicks App Settings under App notifications in android settings menu.
1717
*/
1818
public class SettingsLinkerActivity extends Activity {

source-code/app/src/main/java/org/buildmlearn/toolkit/activity/TemplateEditor.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ protected void onCreate(Bundle savedInstanceState) {
101101
oldFileName = null;
102102
setContentView(R.layout.activity_template_editor);
103103
KeyboardHelper.hideKeyboard(this, findViewById(R.id.toolbar));
104-
KeyboardHelper.hideKeyboard(this,findViewById(R.id.template_editor_listview));
105-
KeyboardHelper.hideKeyboard(this,findViewById(R.id.empty));
104+
KeyboardHelper.hideKeyboard(this, findViewById(R.id.template_editor_listview));
105+
KeyboardHelper.hideKeyboard(this, findViewById(R.id.empty));
106106
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
107107
toolkit = (ToolkitApplication) getApplicationContext();
108108
templateId = getIntent().getIntExtra(Constants.TEMPLATE_ID, -1);
@@ -136,11 +136,11 @@ public void onClick(View v) {
136136
});
137137

138138
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
139-
!= PackageManager.PERMISSION_GRANTED) {
140-
ActivityCompat.requestPermissions(this,
141-
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
142-
PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE_RESULT);
143-
}
139+
!= PackageManager.PERMISSION_GRANTED) {
140+
ActivityCompat.requestPermissions(this,
141+
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
142+
PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE_RESULT);
143+
}
144144
}
145145

146146
/**
@@ -223,14 +223,14 @@ private void populateListView(final BaseAdapter adapter) {
223223
if (templateEdtiorList == null) {
224224
templateEdtiorList = (ListView) findViewById(R.id.template_editor_listview);
225225
}
226-
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
227-
View templateHeader = inflater.inflate(R.layout.listview_header_template, templateEdtiorList, false);
228-
templateEdtiorList.addHeaderView(templateHeader, null, false);
226+
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
227+
View templateHeader = inflater.inflate(R.layout.listview_header_template, templateEdtiorList, false);
228+
templateEdtiorList.addHeaderView(templateHeader, null, false);
229229

230-
EditText authorEditText = (EditText) findViewById(R.id.author_name);
231-
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
232-
assert authorEditText != null;
233-
authorEditText.setText(preferences.getString(getString(R.string.key_user_name), ""));
230+
EditText authorEditText = (EditText) findViewById(R.id.author_name);
231+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
232+
assert authorEditText != null;
233+
authorEditText.setText(preferences.getString(getString(R.string.key_user_name), ""));
234234

235235
setAdapter(adapter);
236236

@@ -552,7 +552,7 @@ public void restoreSelectedView() {
552552
if (selectedView instanceof CardView) {
553553
((CardView) selectedView).setCardBackgroundColor(Color.WHITE);
554554
} else {
555-
selectedView.setBackgroundResource(0);
555+
selectedView.setBackgroundResource(0);
556556
}
557557
}
558558

@@ -683,8 +683,8 @@ private String saveProject() {
683683
@Override
684684
public void onBackPressed() {
685685
super.onBackPressed();
686-
if (saveDraft()!=null)
687-
Toast.makeText(getApplicationContext(),"Saved in Draft!",Toast.LENGTH_SHORT).show();
686+
if (saveDraft() != null)
687+
Toast.makeText(getApplicationContext(), "Saved in Draft!", Toast.LENGTH_SHORT).show();
688688

689689
}
690690

@@ -739,24 +739,24 @@ private String saveDraft() {
739739

740740
int draftFileIndex = 0;
741741
File draftDir = new File(toolkit.getDraftDir());
742-
String probableFileName = "draft"+draftFileIndex+ ".buildmlearn";
742+
String probableFileName = "draft" + draftFileIndex + ".buildmlearn";
743743
File probableFile = new File(draftDir, probableFileName);
744744

745-
while(probableFile.exists()) {
745+
while (probableFile.exists()) {
746746
draftFileIndex++;
747-
probableFileName = "draft"+draftFileIndex+ ".buildmlearn";
747+
probableFileName = "draft" + draftFileIndex + ".buildmlearn";
748748
probableFile = new File(draftDir, probableFileName);
749749
}
750750

751751
//Create temporary File, if that file content matches with OldContent
752752
// Then Don't make Draft
753753
File tempFile = new File(toolkit.getDraftDir(), ".temp");
754754
File oldFile = null;
755-
if (oldFileName!=null)
755+
if (oldFileName != null)
756756
oldFile = new File(oldFileName);
757757

758758
FileUtils.saveXmlFile(toolkit.getDraftDir(), ".temp", doc);
759-
if (oldFile == null || !FileUtils.equalContent(tempFile,oldFile)) {
759+
if (oldFile == null || !FileUtils.equalContent(tempFile, oldFile)) {
760760
tempFile.renameTo(probableFile);
761761
return toolkit.getDraftDir() + probableFileName;
762762
} else {
@@ -768,7 +768,7 @@ private String saveDraft() {
768768
} catch (ParserConfigurationException e) {
769769
e.printStackTrace();
770770
}
771-
return null;
771+
return null;
772772
}
773773

774774

@@ -832,7 +832,7 @@ private void parseSavedFile(String path) {
832832
populateMetaView(selectedTemplate.loadProjectMetaEditor(this, doc));
833833
}
834834
File draftDir = new File(toolkit.getDraftDir());
835-
if (fXmlFile.getParentFile().compareTo(draftDir) ==0 ) {
835+
if (fXmlFile.getParentFile().compareTo(draftDir) == 0) {
836836
//If Draft File
837837
fXmlFile.delete();
838838
}
@@ -880,9 +880,9 @@ private void setAdapterMeta(BaseAdapter adapter) {
880880
@Override
881881
protected void onStop() {
882882
super.onStop();
883-
if(mApkGenerationDialog!=null) {
883+
if (mApkGenerationDialog != null) {
884884
mApkGenerationDialog.dismiss();
885-
mApkGenerationDialog=null;
885+
mApkGenerationDialog = null;
886886
}
887887
}
888888

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/NavigationDrawerMenuAdapter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/**
2323
* @brief Adapter used for showing menus in the side panel
24-
*
24+
* <p/>
2525
* Created by Abhishek on 21/04/15.
2626
*/
2727
public class NavigationDrawerMenuAdapter extends BaseAdapter {
@@ -52,20 +52,23 @@ public NavigationDrawerMenuAdapter(Context context, LayoutInflater inflater) {
5252
public int getCount() {
5353
return sections.length;
5454
}
55+
5556
/**
5657
* {@inheritDoc}
5758
*/
5859
@Override
5960
public Section getItem(int position) {
6061
return sections[position];
6162
}
63+
6264
/**
6365
* {@inheritDoc}
6466
*/
6567
@Override
6668
public long getItemId(int position) {
6769
return position;
6870
}
71+
6972
/**
7073
* {@inheritDoc}
7174
*/
@@ -101,7 +104,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
101104
tv.setCompoundDrawablesWithIntrinsicBounds(sectionIcon, null, null, null);
102105
tv.setBackgroundColor(backgroundColor);
103106
} else if (menu.getType() == Section.SECTION_DIVIDER && convertView == null) {
104-
convertView = inflater.inflate(R.layout.item_section_divider, parent, false);
107+
convertView = inflater.inflate(R.layout.item_section_divider, parent, false);
105108
}
106109
return convertView;
107110
}

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/SavedProjectAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/**
1818
* @brief Adapter used for showing saved projects in a list
19-
*
19+
* <p/>
2020
* Created by Abhishek on 01-06-2015.
2121
*/
2222
public class SavedProjectAdapter extends BaseAdapter {

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/TemplateAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
/**
2727
* @brief Adapter used for showing Templates available in the toolkit
28-
* <p>
28+
* <p/>
2929
* Created by Abhishek on 23-05-2015.
3030
*/
3131
public class TemplateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

source-code/app/src/main/java/org/buildmlearn/toolkit/adapter/TutorialAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
/**
2020
* @brief Adapter used for showing tutorial
21-
*
21+
* <p/>
2222
* Created by abhishek on 03/08/15 at 10:52 PM.
2323
*/
2424
public class TutorialAdapter extends PagerAdapter {

0 commit comments

Comments
 (0)