Skip to content

Commit df55a52

Browse files
committed
Androidstudio cleanup+adding color to title view
1 parent f1be02a commit df55a52

31 files changed

+153
-371
lines changed

MobileOrg/libs/httpcore-4.0.1.jar

-169 KB
Binary file not shown.

MobileOrg/src/main/java/com/matburt/mobileorg/Gui/Outline/OutlineItem.java

Lines changed: 2 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.text.TextUtils;
1414
import android.text.style.ForegroundColorSpan;
1515
import android.text.style.StyleSpan;
16+
import android.util.Log;
1617
import android.view.Gravity;
1718
import android.view.View;
1819
import android.widget.Button;
@@ -39,8 +40,7 @@ public class OutlineItem extends RecyclerView.ViewHolder {
3940
private TextView tagsView;
4041
private Button todoButton;
4142
public TextView levelView;
42-
private boolean levelFormatting = true;
43-
43+
4444
public OutlineItem(View view) {
4545
super(view);
4646
mView = view;
@@ -60,192 +60,5 @@ public OutlineItem(View view) {
6060
public String toString() {
6161
return super.toString() + " '" + levelView.getText() + "'";
6262
}
63-
64-
// private OnClickListener todoClick = new OnClickListener() {
65-
// @Override
66-
// public void onClick(View v) {
67-
// createTodoDialog().show();
68-
// }
69-
// };
70-
71-
private Dialog createTodoDialog() {
72-
// ArrayList<String> todos = PreferenceUtils.getSelectedTodos();
73-
//
74-
// if (todos.size() == 0)
75-
// todos = OrgProviderUtils.getTodos(getContext()
76-
// .getContentResolver());
77-
//
78-
// final ArrayList<String> todoList = todos;
79-
// AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
80-
// builder.setTitle(getResources().getString(R.string.todo_state))
81-
// .setItems(todoList.toArray(new CharSequence[todoList.size()]),
82-
// new DialogInterface.OnClickListener() {
83-
// @Override
84-
// public void onClick(DialogInterface dialog,
85-
// int which) {
86-
// String selectedTodo = todoList.get(which);
87-
// setNewTodo(selectedTodo);
88-
// }
89-
// });
90-
// return builder.create();
91-
return null;
92-
}
93-
94-
private void setNewTodo(String selectedTodo) {
95-
// if (selectedTodo.equals(node.todo))
96-
// return;
97-
//
98-
// ContentResolver resolver = getContext().getContentResolver();
99-
//
100-
// OrgNode newNode;
101-
// try {
102-
// newNode = new OrgNode(node.id, resolver);
103-
// } catch (OrgNodeNotFoundException e) {
104-
// e.printStackTrace();
105-
// return;
106-
// }
107-
// newNode.todo = selectedTodo;
108-
// node.generateApplyWriteEdits(newNode, null, resolver);
109-
// node.write(resolver);
110-
// OrgUtils.announceSyncDone(getContext());
111-
}
112-
113-
private OrgNode node;
114-
115-
public void setLevelFormating(boolean enabled) {
116-
this.levelFormatting = enabled;
117-
}
118-
119-
public void setup(OrgNode node, boolean expanded, DefaultTheme theme, ContentResolver resolver) {
120-
this.node = node;
121-
setupTags(node.tags, node.tags_inherited, theme);
122-
123-
SpannableStringBuilder titleSpan = new SpannableStringBuilder(node.name);
124-
125-
if(node.name.startsWith(OrgFileParser.BLOCK_SEPARATOR_PREFIX)) {
126-
setupAgendaBlock(titleSpan, theme);
127-
return;
128-
}
129-
130-
if (levelFormatting)
131-
applyLevelFormating(theme, node.level, titleSpan);
132-
setupTitle(node.name, theme, titleSpan);
133-
setupPriority(node.priority, theme, titleSpan);
134-
setupTodo(node.todo, theme, resolver);
135-
136-
if (levelFormatting)
137-
applyLevelIndentation(node.level, titleSpan);
138-
139-
if(!expanded)
140-
setupChildrenIndicator(node, resolver, theme, titleSpan);
141-
142-
titleSpan.setSpan(new StyleSpan(Typeface.NORMAL), 0, titleSpan.length(), 0);
143-
titleView.setText(titleSpan);
144-
}
145-
146-
public void setupChildrenIndicator(OrgNode node, ContentResolver resolver,
147-
DefaultTheme theme, SpannableStringBuilder titleSpan) {
148-
if (node.hasChildren(resolver)) {
149-
titleSpan.append("...");
150-
titleSpan.setSpan(new ForegroundColorSpan(theme.defaultForeground),
151-
titleSpan.length() - "...".length(), titleSpan.length(), 0);
152-
}
153-
}
154-
155-
public void setupTodo(String todo, DefaultTheme theme, ContentResolver resolver) {
156-
if(!TextUtils.isEmpty(todo)) {
157-
Spannable todoSpan = new SpannableString(todo + " ");
158-
159-
boolean active = OrgProviderUtils.isTodoActive(todo, resolver);
160-
161-
todoSpan.setSpan(new ForegroundColorSpan(active ? theme.c1Red : theme.caLGreen), 0,
162-
todo.length(), 0);
163-
todoButton.setText(todoSpan);
164-
todoButton.setVisibility(View.VISIBLE);
165-
} else {
166-
todoButton.setVisibility(View.GONE);
167-
}
168-
}
169-
170-
public static void setupPriority(String priority, DefaultTheme theme, SpannableStringBuilder titleSpan) {
171-
if (priority != null && !TextUtils.isEmpty(priority)) {
172-
Spannable prioritySpan = new SpannableString(priority + " ");
173-
prioritySpan.setSpan(new ForegroundColorSpan(theme.c3Yellow), 0,
174-
priority.length(), 0);
175-
titleSpan.insert(0, prioritySpan);
176-
}
177-
}
178-
179-
public void applyLevelIndentation(long level, SpannableStringBuilder item) {
180-
String indentString = "";
181-
for(int i = 0; i < level; i++)
182-
indentString += " ";
183-
184-
this.levelView.setText(indentString);
185-
}
186-
187-
public static void applyLevelFormating(DefaultTheme theme, long level, SpannableStringBuilder item) {
188-
item.setSpan(
189-
new ForegroundColorSpan(theme.levelColors[(int) Math
190-
.abs((level) % theme.levelColors.length)]), 0, item
191-
.length(), 0);
192-
}
193-
194-
public void setupTitle(String name, DefaultTheme theme, SpannableStringBuilder titleSpan) {
195-
titleView.setGravity(Gravity.LEFT);
196-
titleView.setTextSize(PreferenceUtils.getFontSize());
197-
198-
if (name.startsWith("COMMENT"))
199-
titleSpan.setSpan(new ForegroundColorSpan(theme.gray), 0,
200-
"COMMENT".length(), 0);
201-
else if (name.equals("Archive"))
202-
titleSpan.setSpan(new ForegroundColorSpan(theme.gray), 0,
203-
"Archive".length(), 0);
204-
205-
formatLinks(theme, titleSpan);
206-
}
207-
208-
public void setupAgendaBlock(SpannableStringBuilder titleSpan, DefaultTheme theme) {
209-
titleSpan.delete(0, OrgFileParser.BLOCK_SEPARATOR_PREFIX.length());
210-
211-
titleSpan.setSpan(new ForegroundColorSpan(theme.defaultForeground), 0,
212-
titleSpan.length(), 0);
213-
titleSpan.setSpan(new StyleSpan(Typeface.BOLD), 0,
214-
titleSpan.length(), 0);
215-
216-
titleView.setTextSize(PreferenceUtils.getFontSize() + 4);
217-
//titleView.setBackgroundColor(theme.c4Blue);
218-
titleView.setGravity(Gravity.CENTER_VERTICAL
219-
| Gravity.CENTER_HORIZONTAL);
220-
221-
titleView.setText(titleSpan);
222-
}
223-
224-
public static final Pattern urlPattern = Pattern.compile("\\[\\[[^\\]]*\\]\\[([^\\]]*)\\]\\]");
225-
private static void formatLinks(DefaultTheme theme, SpannableStringBuilder titleSpan) {
226-
Matcher matcher = urlPattern.matcher(titleSpan);
227-
while(matcher.find()) {
228-
titleSpan.delete(matcher.start(), matcher.end());
229-
titleSpan.insert(matcher.start(), matcher.group(1));
230-
231-
titleSpan.setSpan(new ForegroundColorSpan(theme.c4Blue),
232-
matcher.start(), matcher.start() + matcher.group(1).length(), 0);
233-
234-
matcher = urlPattern.matcher(titleSpan);
235-
}
236-
}
237-
238-
public void setupTags(String tags, String tagsInherited, DefaultTheme theme) {
239-
if(!TextUtils.isEmpty(tags) || !TextUtils.isEmpty(tagsInherited)) {
240-
if (!TextUtils.isEmpty(tagsInherited))
241-
tagsView.setText(tags + "::" + tagsInherited);
242-
else
243-
tagsView.setText(tags);
244-
245-
tagsView.setTextColor(theme.gray);
246-
tagsView.setVisibility(View.VISIBLE);
247-
} else
248-
tagsView.setVisibility(View.GONE);
249-
}
25063

25164
}

MobileOrg/src/main/java/com/matburt/mobileorg/Gui/Wizard/WideLinearLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected void onMeasure(int w, int h) {
2828
int height = MeasureSpec.getSize(h);
2929
// and its children
3030
for (int i = 0; i < getChildCount(); i++) {
31-
View page = (View) getChildAt(i);
31+
View page = getChildAt(i);
3232
// page.measure(screenWidth,hs);
3333
ViewGroup.LayoutParams lp = page.getLayoutParams();
3434
lp.width = screenWidth;

MobileOrg/src/main/java/com/matburt/mobileorg/Gui/Wizard/WizardActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public void onCreate(Bundle savedInstanceState) {
3838
syncGroup.clearCheck();
3939
syncGroup.setOnCheckedChangeListener(this);
4040

41-
syncWebDav = ((RadioButton) findViewById(R.id.sync_webdav)).getId();
42-
syncDropBox = ((RadioButton) findViewById(R.id.sync_dropbox)).getId();
43-
syncUbuntuOne = ((RadioButton) findViewById(R.id.sync_ubuntuone))
41+
syncWebDav = findViewById(R.id.sync_webdav).getId();
42+
syncDropBox = findViewById(R.id.sync_dropbox).getId();
43+
syncUbuntuOne = findViewById(R.id.sync_ubuntuone)
4444
.getId();
45-
syncSdCard = ((RadioButton) findViewById(R.id.sync_sdcard)).getId();
46-
syncNull = ((RadioButton) findViewById(R.id.sync_null)).getId();
47-
syncSSH = ((RadioButton) findViewById(R.id.sync_ssh)).getId();
45+
syncSdCard = findViewById(R.id.sync_sdcard).getId();
46+
syncNull = findViewById(R.id.sync_null).getId();
47+
syncSSH = findViewById(R.id.sync_ssh).getId();
4848

4949
ViewTreeObserver observer = wizardView.getViewTreeObserver();
5050
if (observer.isAlive()) {

MobileOrg/src/main/java/com/matburt/mobileorg/Gui/Wizard/WizardView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void disableAllNextActions(int page) {
8484
if (container != null)
8585
for (int i = page; i < container.getChildCount(); i++) {
8686
// get the pageview container
87-
View pageContainer = (View) container.getChildAt(i);
87+
View pageContainer = container.getChildAt(i);
8888
// last page doesn't have a next button
8989
View nextButton = pageContainer
9090
.findViewById(R.id.wizard_next_button);
@@ -98,7 +98,7 @@ public void disableAllNextActions(int page) {
9898
// disable/enable all buttons for given page
9999
public void setNavButtonStateOnPage(int page, boolean state, int page_type) {
100100
// get the pageview container
101-
View pageContainer = (View) container.getChildAt(page);
101+
View pageContainer = container.getChildAt(page);
102102
Button prevButton = (Button) pageContainer
103103
.findViewById(R.id.wizard_previous_button);
104104
Button nextButton = (Button) pageContainer
@@ -256,7 +256,7 @@ public void onClick(View v) {
256256

257257
// hide keyboard if showing
258258
private void hideKeyboard() {
259-
InputMethodManager imm = (InputMethodManager) ((Activity) getContext())
259+
InputMethodManager imm = (InputMethodManager) getContext()
260260
.getSystemService(Context.INPUT_METHOD_SERVICE);
261261
imm.hideSoftInputFromWindow(getWindowToken(), 0);
262262
}

MobileOrg/src/main/java/com/matburt/mobileorg/Gui/Wizard/Wizards/UbuntuOneWizard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void onClick(View v) {
6464

6565
private void loginUbuntuOne() {
6666
final UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer(
67-
(Context) context);
67+
context);
6868
uos.username = ubuntuoneEmail.getText().toString();
6969
uos.password = ubuntuonePass.getText().toString();
7070

MobileOrg/src/main/java/com/matburt/mobileorg/Gui/Wizard/Wizards/Wizard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void showToastRemote(String message) {
8282

8383
public enum TYPE {
8484
WebDAV, Dropbox, Ubuntu, SDCard, SSH, Null
85-
};
85+
}
8686

8787
public static Wizard getWizard(TYPE type, WizardView wizardView,
8888
Context context) {

MobileOrg/src/main/java/com/matburt/mobileorg/OrgData/OrgEdit.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public enum TYPE {
2020
ARCHIVE_SIBLING,
2121
DELETE,
2222
ADDHEADING
23-
};
24-
23+
}
24+
2525
public TYPE type = null;
2626
public String nodeId = "";
2727
public String title = "";

MobileOrg/src/main/java/com/matburt/mobileorg/OrgData/OrgFile.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,8 @@ public boolean doesFileExist(ContentResolver resolver) {
8585
Files.DEFAULT_COLUMNS, null, null, null);
8686
int count = cursor.getCount();
8787
cursor.close();
88-
89-
if(count > 0)
90-
return true;
91-
else
92-
return false;
88+
89+
return count > 0;
9390
}
9491

9592
public OrgNode getOrgNode(ContentResolver resolver) {
@@ -165,16 +162,11 @@ public boolean isEncrypted() {
165162
public boolean generateEditsForFile() {
166163
if(filename.equals(CAPTURE_FILE))
167164
return false;
168-
if(filename.equals(AGENDA_FILE))
169-
return false;
170-
return true;
165+
return !filename.equals(AGENDA_FILE);
171166
}
172167

173168
public boolean equals(OrgFile file) {
174-
if (filename.equals(file.filename) && name.equals(file.name))
175-
return true;
176-
else
177-
return false;
169+
return filename.equals(file.filename) && name.equals(file.name);
178170
}
179171

180172
public String toString(ContentResolver resolver) {

MobileOrg/src/main/java/com/matburt/mobileorg/OrgData/OrgNode.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,8 @@ public boolean hasChildren(ContentResolver resolver) {
269269

270270
int childCount = childCursor.getCount();
271271
childCursor.close();
272-
273-
if(childCount > 0)
274-
return true;
275-
else
276-
return false;
272+
273+
return childCount > 0;
277274
}
278275

279276
public static boolean hasChildren (long node_id, ContentResolver resolver) {
@@ -562,12 +559,9 @@ public String toString() {
562559
}
563560

564561
public boolean equals(OrgNode node) {
565-
if (name.equals(node.name) && tags.equals(node.tags)
562+
return name.equals(node.name) && tags.equals(node.tags)
566563
&& priority.equals(node.priority) && todo.equals(node.todo)
567-
&& payload.equals(node.payload))
568-
return true;
569-
else
570-
return false;
564+
&& payload.equals(node.payload);
571565
}
572566

573567

MobileOrg/src/main/java/com/matburt/mobileorg/OrgData/OrgNodeTimeDate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public enum TYPE {
2222
Deadline,
2323
Timestamp,
2424
InactiveTimestamp
25-
};
25+
}
2626

2727
public OrgNodeTimeDate(TYPE type) {
2828
this.type = type;

MobileOrg/src/main/java/com/matburt/mobileorg/OrgData/OrgProviderUtils.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,8 @@ public static boolean isTodoActive(String todo, ContentResolver resolver) {
315315
cursor.moveToFirst();
316316
int isdone = cursor.getInt(cursor.getColumnIndex(Todos.ISDONE));
317317
cursor.close();
318-
319-
if(isdone == 0)
320-
return true;
321-
else
322-
return false;
318+
319+
return isdone == 0;
323320
}
324321

325322
return false;

0 commit comments

Comments
 (0)