NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.blogspot.jddevelop.android.marketmarks;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListPopupWindow;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.blogspot.jddevelop.android.marketmarks.util.CursorUtils;
import com.blogspot.jddevelop.android.marketmarks.util.DateUtils;
import com.blogspot.jddevelop.android.marketmarks.util.UiUtils;

public class NewBookmarkManuallyActivity extends SherlockActivity {

private class LoadPackageDetailsTask extends AsyncTask<Void, Void, CheckUpdatesResult> {

private LoadPackageDetails fLoadPackageDetails;

public LoadPackageDetailsTask() {
fLoadPackageDetails = new LoadPackageDetails(NewBookmarkManuallyActivity.this, this);
}

@Override
protected void onPreExecute() {
fProgressDialog = new ProgressDialog(NewBookmarkManuallyActivity.this);
fProgressDialog.setTitle(R.string.please_wait);
fProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
fProgressDialog.setMessage(getString(R.string.retrieve_data_now));
fProgressDialog.setCancelable(true);
fProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

public void onCancel(DialogInterface dialog) {
cancel(true);
}

});
fProgressDialog.setButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
cancel(true);
}

});
fProgressDialog.show();
}

@Override
protected CheckUpdatesResult doInBackground(Void... arg0) {
return fLoadPackageDetails.load(fPackageName);
}

@Override
protected void onPostExecute(CheckUpdatesResult result) {
if (result.hasError) {
if (fTitle != null) {
tvTitle.setText(fTitle);
tvPackageName.setText(fPackageName);

initLabelsTextView();
tvTitle.setEnabled(true);
tvNotes.setEnabled(true);

} else {
btnSave.setEnabled(false);

}

fProgressDialog.dismiss();
UiUtils.showToastShort(NewBookmarkManuallyActivity.this, R.string.error_occurred);

return;

}

if (result.notFound || result.deleted) {
btnSave.setEnabled(false);
fProgressDialog.dismiss();
UiUtils.showToastShort(NewBookmarkManuallyActivity.this, R.string.package_not_found);

return;

}

fTitle = fLoadPackageDetails.getTitle();
tvTitle.setText(fTitle);

fIcon = fLoadPackageDetails.getIcon();
Bitmap bitmap = BitmapFactory.decodeByteArray(fIcon, 0, fIcon.length);
ivAppIcon.setImageBitmap(bitmap);

tvPackageName.setText(fPackageName);

fTime = fLoadPackageDetails.getTime();
long date = fTime;
if (0 < date) {
tvUpdated.setText(DateUtils.getDateTimeString(NewBookmarkManuallyActivity.this, date));

} else {
tvUpdated.setText(R.string.unknown);

}

fCurrentVersion = fLoadPackageDetails.getCurrentVersion();
if (fCurrentVersion == null) {
tvCurrentVersion.setText(R.string.unknown);

} else if (-1 < Arrays.binarySearch(fVariesWithDeviceEntries, fCurrentVersion)) {
boolean isJapanese = Locale.JAPANESE.getLanguage().equals(Locale.getDefault().getLanguage());
tvCurrentVersion.setText(fVariesWithDeviceEntries[isJapanese ? 1 : 0]);

} else {
tvCurrentVersion.setText(fCurrentVersion);

}

fPrice = fLoadPackageDetails.getPrice();
if (fPrice == null) {
tvPrice.setText(R.string.unknown);

} else if (!"0".equals(fPrice)) {
tvPrice.setText(fPrice);

} else {
tvPrice.setText(R.string.free);

}

initLabelsTextView();
tvTitle.setEnabled(true);
tvNotes.setEnabled(true);

fProgressDialog.dismiss();
}

protected void onCancelled() {
if (fTitle != null) {
tvTitle.setText(fTitle);
tvPackageName.setText(fPackageName);

initLabelsTextView();
tvTitle.setEnabled(true);
tvNotes.setEnabled(true);

} else {
btnSave.setEnabled(false);

}

fProgressDialog.dismiss();
}

}

private ImageView ivAppIcon;

private TextView tvTitle;

private TextView tvPackageName;

private TextView tvUpdated;

private TextView tvCurrentVersion;

private TextView tvPrice;

private Button btnSave;

private Button btnLabels;

private TextView tvNotes;

private Button btnCancel;

private Button btnBack;

private ProgressDialog fProgressDialog;

private String fTitle;

private String fPackageName;

private byte[] fIcon;

private long fTime;

private String fCurrentVersion;

public String fPrice;

private MarketMarksDbAdapter fAdapter;

protected int fPreviousSelectionFolder;

private String[] fVariesWithDeviceEntries;

private long fId = -1;

private ArrayList<CharSequence> fSelectedLabels = new ArrayList<CharSequence>();

protected ListPopupWindow fPopup;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(AppModel.getInstance(getApplicationContext()).getTheme() == 1
? R.style.Theme_Sherlock_Light_DarkActionBar_ForceOverflow
: R.style.Theme_Sherlock_ForceOverflow);
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
setContentView(R.layout.new_package);

fVariesWithDeviceEntries = getResources().getStringArray(R.array.varies_with_device_entries);

final Intent intent = getIntent();
final String action = intent.getAction();
if (Intent.ACTION_EDIT.equals(action)) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

}

// Inflate a "Done" custom action bar view to serve as the "Up"
// affordance.
final ActionBar actionBar = getSupportActionBar();
LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done, null);

// Show the custom action bar view and hide the normal Home icon and
// title.
actionBar.setDisplayOptions(
ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setCustomView(customActionBarView);

View flActionBarDone = customActionBarView.findViewById(R.id.actionbar_done);
// flActionBarDone.setOnClickListener(fController.savePhotoCommand);

ivAppIcon = (ImageView) findViewById(R.id.app_icon);
tvTitle = (TextView) findViewById(R.id.title);
tvPackageName = (TextView) findViewById(R.id.package_name);
tvUpdated = (TextView) findViewById(R.id.updated);
tvCurrentVersion = (TextView) findViewById(R.id.current_version);
tvPrice = (TextView) findViewById(R.id.price);
btnSave = (Button) findViewById(R.id.save_button);
btnLabels = (Button) findViewById(R.id.folder);
tvNotes = (TextView) findViewById(R.id.notes);
btnCancel = (Button) findViewById(R.id.cancel_button);
btnBack = (Button) findViewById(R.id.back_button);
btnLabels.setEnabled(false);

fAdapter = new MarketMarksDbAdapter(getApplicationContext());
fAdapter.open();

if (Intent.ACTION_EDIT.equals(action)) {
fId = intent.getLongExtra(MarketMarks.EXTRA_DETAIL_ID, 0);
fPackageName = getPackageNameByDetailId(fId);
initScreenAsUpdate();
return;

}

fPackageName = NewBookmarkActivity.isValidIntent(intent);
if (fPackageName == null) {
setTitle(R.string.new_package);
processError(R.string.unable_to_retrieve_data);
return;

}

if (fAdapter.existsBookmark(fPackageName)) {
fId = getBookmarkIdByPackageName(fPackageName);
initScreenAsUpdate();
UiUtils.showToastShort(this, R.string.package_has_already_been_saved);
return;
}

setTitle(R.string.new_package);

if (Intent.ACTION_SEND.equals(action)) {
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
fTitle = NewBookmarkActivity.getTitle(subject);

}

initSaveButton();
initCancelButton();
btnBack.setVisibility(View.GONE);

if (MarketMarks.isNetworkAvailable(this)) {
new LoadPackageDetailsTask().execute();

} else {
if (fTitle != null) {
tvTitle.setText(fTitle);
tvPackageName.setText(fPackageName);
tvTitle.setEnabled(true);
}

UiUtils.showToastShort(this, R.string.no_connetion);

}
}

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;

}

return super.onOptionsItemSelected(item);
}

private void processError(int resId) {
btnSave.setVisibility(View.GONE);
btnCancel.setVisibility(View.GONE);
initBackButton();
UiUtils.showToastShort(this, resId);
}

private void onSave() {
String title = tvTitle.getText().toString();
String notes = tvNotes.getText().toString();
String labels = btnLabels.getText().toString();

if (NewBookmarkActivity.onSave(this, fAdapter, fPackageName, title, fIcon, fTime, fCurrentVersion, fPrice, notes, labels)) {
UiUtils.showToastShort(this, R.string.package_saved);
finish();

} else {
UiUtils.showToastShort(this, R.string.error_occurred);

}
}

private void onUpdate(long id) {
TransactionManager tx = new TransactionManager(getApplicationContext());
tx.open();

try {
tx.begin();

fAdapter.updateTitle(id, tvTitle.getText().toString());
fAdapter.updateNotes(id, tvNotes.getText().toString());
fAdapter.deleteLabelsBookmarksByBookmarkId(id);

String labels = btnLabels.getText().toString();
String[] tokens = labels.split(",");
for (String s : tokens) {
String label = s.replaceAll("^ +", "");
if (TextUtils.isEmpty(label)) {
continue;
}

long labelId;
if (fAdapter.existsLabelsByLabel(label)) {
Cursor cursor = fAdapter.getLabelsByLabel(label);
cursor.moveToNext();
labelId = cursor.getLong(0);

} else {
labelId = fAdapter.createLabel(label);

}
fAdapter.createLabelsBookmarks(labelId, id);
}

tx.commit();

UiUtils.showToastShort(this, R.string.package_updated);
finish();

} catch (SQLException e) {
tx.rollback();
UiUtils.showToastShort(this, R.string.error_occurred);

}
}

private void initScreenAsUpdate() {
setTitle(R.string.edit_package);

// Setup views.
tvTitle.setEnabled(true);
initLabelsTextView();
tvNotes.setEnabled(true);
initSaveButton();
initCancelButton();
btnBack.setVisibility(View.GONE);

BookmarkCursor cursor = fAdapter.fetchBookmark(fId);
cursor.moveToNext();

tvTitle.setText(cursor.getTitle());

Bitmap bitmap = MarketMarks.loadIcon(this, fAdapter, fPackageName, fId);
ivAppIcon.setImageBitmap(bitmap);

tvPackageName.setText(fPackageName);

long date = cursor.getDate();
if (0 < date) {
tvUpdated.setText(DateUtils.getDateTimeString(this, date));

} else {
tvUpdated.setText(R.string.unknown);

}

String version = cursor.getVersion();
if (version == null) {
tvCurrentVersion.setText(R.string.unknown);

} else if (-1 < Arrays.binarySearch(fVariesWithDeviceEntries, version)) {
boolean isJapanese = Locale.JAPANESE.getLanguage().equals(Locale.getDefault().getLanguage());
tvCurrentVersion.setText(fVariesWithDeviceEntries[isJapanese ? 1 : 0]);

} else {
tvCurrentVersion.setText(version);

}

String price = cursor.getPrice();
if (price == null) {
tvPrice.setText(R.string.unknown);

} else if (!"0".equals(price)) {
tvPrice.setText(price);

} else {
tvPrice.setText(R.string.free);

}

Cursor labelsCursor = fAdapter.getLabelsByBookmarkId(fId);
String[] labels = CursorUtils.toStringArray(labelsCursor, 0);
labelsCursor.close();
btnLabels.setText(TextUtils.join(", ", labels));
int count = labels.length;
for (int i = 0; i < count; i++) {
fSelectedLabels.add(labels[i]);

}

if (!cursor.isNull(10)) {
tvNotes.setText(cursor.getString(10));

}

cursor.close();
}

private void initSaveButton() {
if (fId != -1) {
btnSave.setText(R.string.update);

}

btnSave.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
if (TextUtils.isEmpty(tvTitle.getText().toString())) {
UiUtils.showToastShort(NewBookmarkManuallyActivity.this, R.string.enter_title);

return;

}

if (fId != -1) {
onUpdate(fId);

} else {
onSave();

}
}

});
}

private void initCancelButton() {
btnCancel.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
finish();
}

});
}

private void initBackButton() {
btnBack.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
finish();
}

});
}

private void initLabelsTextView() {
btnLabels.setEnabled(true);

btnLabels.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
Cursor labels = fAdapter.getAllLabels();
final int count = labels.getCount();
final String[] items = new String[count + 1];
System.arraycopy(CursorUtils.toStringArray(labels, 1), 0, items, 0, count);
labels.close();
items[count] = getString(R.string.new_label);

if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) {
if (fPopup != null && fPopup.isShowing()) {
fPopup.dismiss();
return;
}

fPopup = new ListPopupWindow(NewBookmarkManuallyActivity.this, null);
fPopup.setAnchorView(btnLabels);
fPopup.setAdapter(new ArrayAdapter<String>(NewBookmarkManuallyActivity.this, R.layout.label_list_item_multiple_choice, items));
fPopup.setModal(true);
fPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
fPopup.show();

ListView listView = fPopup.getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
for (int i = 0; i < count; i++) {
if (fSelectedLabels.contains(items[i])) {
listView.setItemChecked(i, true);

}
}

listView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (count <= position) {
fPopup.dismiss();
UiUtils.showNewLabelDialog(NewBookmarkManuallyActivity.this, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
EditTextDialog etd = (EditTextDialog) dialog;
String label = etd.getText().toString();
fAdapter.createLabel(label);
fSelectedLabels.add(label);
btnLabels.setText(TextUtils.join(", ", fSelectedLabels));
}

});
return;

}

if (!fSelectedLabels.contains(items[position])) {
fSelectedLabels.add(items[position]);

} else {
fSelectedLabels.remove(items[position]);

}

btnLabels.setText(TextUtils.join(", ", fSelectedLabels));
}

});

} else {
boolean[] checkedColours = new boolean[count + 1];
for (int i = 0; i < count; i++) {
checkedColours[i] = fSelectedLabels.contains(items[i]);
}

AlertDialog.Builder builder = new AlertDialog.Builder(NewBookmarkManuallyActivity.this);
builder.setTitle(R.string.labels);
builder.setMultiChoiceItems(items, checkedColours, new DialogInterface.OnMultiChoiceClickListener() {

public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (count <= which) {
dialog.dismiss();
UiUtils.showNewLabelDialog(NewBookmarkManuallyActivity.this, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
EditTextDialog etd = (EditTextDialog) dialog;
String label = etd.getText().toString();
fAdapter.createLabel(label);
fSelectedLabels.add(label);
btnLabels.setText(TextUtils.join(", ", fSelectedLabels));
}

});
return;

}

if (isChecked) {
fSelectedLabels.add(items[which]);

} else {
fSelectedLabels.remove(items[which]);

}

btnLabels.setText(TextUtils.join(", ", fSelectedLabels));
}

});
builder.setNeutralButton(R.string.close, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}

});
AlertDialog dialog = builder.create();
dialog.show();
}

}

});
}

private String getPackageNameByDetailId(long id) {
BookmarkCursor cursor = fAdapter.fetchBookmark(id);
cursor.moveToNext();
String packageName = cursor.getPackage();
cursor.close();
return packageName;
}

private long getBookmarkIdByPackageName(String packageName) {
BookmarkCursor cursor = fAdapter.fetchBookmark(packageName);
cursor.moveToNext();
long id = cursor.getId();
cursor.close();
return id;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.