Android Open Source - TuxRemote App Fragment

From Project

Back to project page TuxRemote.


The source code is released under:

GNU General Public License

If you think the Android project TuxRemote listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//  w  w  w  .ja  va  2  s .co  m
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

//import com.squareup.picasso.Picasso;

import java.util.ArrayList;

public class AppFragment extends Fragment {
    private static final String ARG_APP_NAME = "app_name";
    private static final String ARG_HEXAID = "hexaId";
    private static final String ARG_TITLE = "window_title";
    private static final String ARG_PID = "app_pid";
    private static final String ARG_NUMBER = "currentSelectedItem";
    public static final String TAG="AppFragment";
    private static final String ARG_STATIC_APP = "static_app";
    private AppAdapter adapter;
    private ListView listView;
    private ArrayList<Command> cmds;
    private String appName;
    private String appHexaId;
    private String appTitle;
    private String appPid;
    private Context context;
    private AppFragmentCallbacks mCallbacks;
    private int number;
    private boolean isStaticApp;
//    private FadingActionBarHelperBase mFadingHelper;

     * Returns a new instance of this fragment for the given app.
    public static AppFragment newInstance(int position, App app) {
        AppFragment fragment = new AppFragment();
        Bundle args = new Bundle();
        args.putString(ARG_APP_NAME, app.getName());
        args.putString(ARG_HEXAID, app.getHexaId());
        args.putString(ARG_TITLE, app.getTitle());
        args.putString(ARG_PID, app.getPid());
        args.putBoolean(ARG_STATIC_APP, app.isStaticApp());
        args.putInt(ARG_NUMBER, position);
        return fragment;

    public AppFragment() {

    public void onCreate(Bundle savedInstanceState) {

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        cmds = new ArrayList<Command>();
        cmds.addAll(loadFromConfigFile(Global.getStaticContext(), appName, appHexaId, isStaticApp));
//        View view = mFadingHelper.createView(inflater);
//        ImageView img = (ImageView) view.findViewById(;
//        Picasso.with(getActivity().getApplicationContext()).load(TuxRemoteUtils.DEFAULT_ICON_APP).fit().centerInside().into(img);
        View view = inflater.inflate(R.layout.app_fragment, container, false);
        if(view != null) {
            listView = (ListView) view.findViewById(;
            adapter = new AppAdapter(Global.getStaticContext(), cmds);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                    final Command command = cmds.get(position);
                    if (command.getCmd().contains("%file%")) {
                        try {
                            FileSelectorDialog dialog = new FileSelectorDialog(Global.getStaticContext()) {
                                public void customItemClick(File file, String currentDir, String currentParent) {
                                    if (!file.isDir()) {
                                        Log.v("customItemClick", currentDir + file.getFileName());
                                        Command cmd = command.copy();
                                        cmd.setCmd(cmd.getCmd().replace("%file%", currentDir+file.getFileName()));
                                        SSHAsyncTask task = new SSHAsyncTask(cmd);
                        }catch (Exception e){e.printStackTrace();}
                        SSHAsyncTask task = new SSHAsyncTask(command);
        return view;

    private static ArrayList<Command> loadFromConfigFile(Context context, String appName, String appHexaId, boolean isStaticApp) {
        ArrayList<Command> list = new ConfigXML(context).getCommandList(appName);
        if(!isStaticApp) {
        return list;

    public void onAttach(Activity activity) {
        if(getArguments() != null) {
            appName = getArguments().getString(ARG_APP_NAME);
            appHexaId = getArguments().getString(ARG_HEXAID);
            appTitle = getArguments().getString(ARG_TITLE);
            appPid = getArguments().getString(ARG_PID);
            isStaticApp = getArguments().getBoolean(ARG_STATIC_APP);
            number = getArguments().getInt(ARG_NUMBER);
        ((MainActivity) activity).onSectionAttached(appName);
        context = ((MainActivity) activity).getApplicationContext();
        try {
            mCallbacks = (AppFragmentCallbacks) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");

    private static class AppAdapter extends BaseAdapter {

        private final Context context;
        private final ArrayList<Command> list;

        AppAdapter(Context c, ArrayList<Command> cmds){
            context = c;
            list = cmds;

        public int getCount() {
            return list.size();

        public Object getItem(int i) {
            return list.get(i);

        public long getItemId(int i) {
            return i;

        public View getView(int position, View convertView, ViewGroup viewGroup) {
            Command cmd = (Command) this.getItem(position);
            ViewHolder holder;
            if(convertView == null)
                holder = new ViewHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.row_cmd, viewGroup, false);
       = (TextView) convertView.findViewById(;
                holder.icon = (ImageView) convertView.findViewById(;
                holder = (ViewHolder) convertView.getTag();

            cmd.setIconToView(context, holder.icon);
            return convertView;

        private class ViewHolder {
            public TextView name;
            public ImageView icon;

     * Callbacks interface that all activities using this fragment must implement.
    public static interface AppFragmentCallbacks {
         * Called when an item in the navigation drawer is selected.
        void onCommandClose(int position);

Java Source Code List