mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
user registration/signing in refactoring (in progress)
This commit is contained in:
parent
aaae97c551
commit
b483946d4d
10 changed files with 164 additions and 268 deletions
113
src/org/geometerplus/android/fbreader/network/MenuActivity.java
Normal file
113
src/org/geometerplus/android/fbreader/network/MenuActivity.java
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (C) 2010-2011 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.android.fbreader.network;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.os.Bundle;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.android.fbreader.api.PluginApi;
|
||||
|
||||
abstract class MenuActivity extends ListActivity implements AdapterView.OnItemClickListener {
|
||||
protected List<PluginApi.MenuActionInfo> myInfos;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
myInfos = new ArrayList<PluginApi.MenuActionInfo>();
|
||||
|
||||
init();
|
||||
|
||||
try {
|
||||
startActivityForResult(new Intent(getAction(), getIntent().getData()), 0);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
if (myInfos.size() == 1) {
|
||||
runItem(myInfos.get(0));
|
||||
}
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
setListAdapter(new ActionListAdapter());
|
||||
getListView().setOnItemClickListener(this);
|
||||
}
|
||||
|
||||
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
runItem(myInfos.get(position));
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (intent != null) {
|
||||
final List<PluginApi.MenuActionInfo> actions =
|
||||
intent.<PluginApi.MenuActionInfo>getParcelableArrayListExtra(
|
||||
PluginApi.PluginInfo.KEY
|
||||
);
|
||||
if (actions != null) {
|
||||
myInfos.addAll(actions);
|
||||
}
|
||||
if (myInfos.size() == 0) {
|
||||
finish();
|
||||
return;
|
||||
} else if (myInfos.size() == 1) {
|
||||
runItem(myInfos.get(0));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
Collections.sort(myInfos);
|
||||
((ActionListAdapter)getListAdapter()).notifyDataSetChanged();
|
||||
getListView().invalidateViews();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void init();
|
||||
protected abstract String getAction();
|
||||
protected abstract void runItem(final PluginApi.MenuActionInfo info);
|
||||
|
||||
private class ActionListAdapter extends BaseAdapter {
|
||||
public final int getCount() {
|
||||
return myInfos.size();
|
||||
}
|
||||
|
||||
public final PluginApi.MenuActionInfo getItem(int position) {
|
||||
return myInfos.get(position);
|
||||
}
|
||||
|
||||
public final long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
public View getView(int position, View convertView, final ViewGroup parent) {
|
||||
final View view = convertView != null
|
||||
? convertView
|
||||
: LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_item, parent, false);
|
||||
((TextView)view).setText(getItem(position).MenuItemName);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue