Android Open Source - remoteyourcam-usb Property Displayer






From Project

Back to project page remoteyourcam-usb.

License

The source code is released under:

Apache License

If you think the Android project remoteyourcam-usb 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

/**
 * Copyright 2013 Nils Assbeck, Guersel Ayaz and Michael Zoech
 *// w  w w  .  j a v a2  s.co m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.remoteyourcam.usb;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.remoteyourcam.usb.ptp.Camera;
import com.remoteyourcam.usb.util.DimenUtil;

public class PropertyDisplayer {

    private final PropertyToggle toggleButton;
    private final LinearLayout listContainer;
    private final ListView list;
    private final int property;
    private int[] values = new int[0];
    private int value;
    private final Context context;
    private Camera camera;
    private int biggestValueWidth = -1;
    private PropertyAdapter<?> adapter;
    private int checkboxWidth = -1;
    private boolean dataChanged;
    private final CheckBox autoHideCb;
    private boolean editable;

    public PropertyDisplayer(Context context, View container, LayoutInflater inflater, int property, int toggleBtnId,
            String title) {
        this.context = context;
        this.property = property;
        this.toggleButton = (PropertyToggle) container.findViewById(toggleBtnId);
        toggleButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onToggled();
            }
        });

        // there seems to be a layouting bug when setting this to "", so initialize it at least to " "
        toggleButton.setText(" ");
        toggleButton.setButtonDrawable2(null);

        listContainer = (LinearLayout) inflater.inflate(R.layout.property_listview, null);
        ((TextView) listContainer.findViewById(R.id.title)).setText(title);
        list = (ListView) listContainer.findViewById(android.R.id.list);
        listContainer.setVisibility(View.GONE);
        list.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                camera.setProperty(PropertyDisplayer.this.property, values[position]);
                if (autoHideCb.isChecked()) {
                    toggleButton.setChecked(false);
                    onToggled();
                }
            }
        });
        listContainer.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));

        autoHideCb = (CheckBox) listContainer.findViewById(R.id.autoHideCB);

        CheckBox cb = new CheckBox(context);
        cb.setText("Hide");
        cb.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        checkboxWidth = cb.getMeasuredWidth();
    }

    public void setCamera(Camera camera) {
        this.camera = camera;
    }

    public ToggleButton getToggle() {
        return toggleButton;
    }

    public LinearLayout getList() {
        return listContainer;
    }

    public void setPropertyDesc(int[] values, String[] valuesStrings, Integer[] icons) {
        this.values = values;
        toggleButton.setEnabled(editable && values.length > 0);

        if (icons != null) {
            Drawable drawables[] = new Drawable[icons.length];
            for (int i = 0; i < icons.length; ++i) {
                if (icons[i] == null) {
                    continue;
                }
                Drawable d = context.getResources().getDrawable(icons[i]);
                drawables[i] = d;
                if (biggestValueWidth == -1) {
                    biggestValueWidth = d.getIntrinsicWidth();
                    layoutListView(biggestValueWidth);
                }
            }
            adapter = new PropertyAdapter<Drawable>(context, R.layout.property_icon_list_item, drawables);
        } else {
            String longest = "";
            int longestLength = 0;
            for (String s : valuesStrings) {
                int len = s.length();
                if (len > longestLength) {
                    longest = s;
                    longestLength = len;
                }
            }
            TextView t = new TextView(context);
            // HACK HACK
            if (context.getResources().getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE)) {
                t.setTextAppearance(context, android.R.style.TextAppearance_Large);
            } else {
                t.setTextAppearance(context, android.R.style.TextAppearance_Medium);
            }
            t.setText(longest + " ");
            t.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
            biggestValueWidth = t.getMeasuredWidth();
            layoutListView(biggestValueWidth);
            adapter = new PropertyAdapter<String>(context, R.layout.property_list_item, valuesStrings);
        }
        list.setAdapter(adapter);

        if (toggleButton.isChecked()) {
            if (values.length == 0) {
                listContainer.setVisibility(View.GONE);
            } else {
                listContainer.setVisibility(View.VISIBLE);
                updateCurrentPosition();
            }
        } else {
            dataChanged = true;
        }
    }

    public void setProperty(int value, String text, Integer iconId) {
        this.value = value;
        if (iconId != null) {
            toggleButton.setTextOn("");
            toggleButton.setTextOff("");
            Drawable d = context.getResources().getDrawable(iconId);
            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
            //Drawable[] c = toggleButton.getCompoundDrawables();
            //toggleButton.setCompoundDrawables(c[0], d, c[2], c[3]);
            toggleButton.setButtonDrawable2(d);
            toggleButton.setButtonDrawable(null);
        } else {
            toggleButton.setButtonDrawable(null);
            toggleButton.setTextOn(text);
            toggleButton.setTextOff(text);
        }
        toggleButton.setChecked(toggleButton.isChecked());

        if (toggleButton.isChecked()) {
            updateCurrentPosition();
        } else {
            dataChanged = true;
        }
    }

    private void updateCurrentPosition() {
        for (int i = 0; i < values.length; ++i) {
            if (value == values[i]) {
                if (adapter != null) {
                    adapter.setCurrentPosition(i);
                    if (listContainer.getVisibility() == View.GONE) {
                        list.setSelectionFromTop(i - 3, 0);
                    }
                }
                break;
            }
        }
    }

    public void onToggled() {
        if (toggleButton.isChecked()) {
            if (dataChanged) {
                dataChanged = false;
                updateCurrentPosition();
            }
            listContainer.setVisibility(View.VISIBLE);
        } else {
            listContainer.setVisibility(View.GONE);
        }
    }

    private void layoutListView(int itemWidth) {
        int paddingRight = (int) DimenUtil.dpToPx(context, 8);
        int listWidth = itemWidth + paddingRight + list.getListPaddingLeft() + list.getListPaddingRight()
                + list.getVerticalScrollbarWidth();
        listContainer.getLayoutParams().width = Math.max(checkboxWidth, listWidth);
        listContainer.requestLayout();
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
        toggleButton.setEnabled(editable && values.length > 0);
        if (!editable && toggleButton.isChecked()) {
            toggleButton.setChecked(false);
            onToggled();
        }
    }

    public void setAutoHide(boolean hide) {
        autoHideCb.setChecked(hide);
    }

    public boolean getAutoHide() {
        return autoHideCb.isChecked();
    }
}




Java Source Code List

com.remoteyourcam.usb.AbstractRycApplication.java
com.remoteyourcam.usb.AppConfig.java
com.remoteyourcam.usb.AppSettings.java
com.remoteyourcam.usb.GestureDetector.java
com.remoteyourcam.usb.MainActivity.java
com.remoteyourcam.usb.PictureView.java
com.remoteyourcam.usb.PropertyAdapter.java
com.remoteyourcam.usb.PropertyData.java
com.remoteyourcam.usb.PropertyDisplayer.java
com.remoteyourcam.usb.PropertyToggle.java
com.remoteyourcam.usb.RycApplication.java
com.remoteyourcam.usb.activities.AppSettingsActivity.java
com.remoteyourcam.usb.ptp.Camera.java
com.remoteyourcam.usb.ptp.EosCamera.java
com.remoteyourcam.usb.ptp.EosConstants.java
com.remoteyourcam.usb.ptp.FocusPoint.java
com.remoteyourcam.usb.ptp.NikonCamera.java
com.remoteyourcam.usb.ptp.PacketUtil.java
com.remoteyourcam.usb.ptp.PtpAction.java
com.remoteyourcam.usb.ptp.PtpCamera.java
com.remoteyourcam.usb.ptp.PtpConstants.java
com.remoteyourcam.usb.ptp.PtpPropertyHelper.java
com.remoteyourcam.usb.ptp.PtpService.java
com.remoteyourcam.usb.ptp.PtpUsbConnection.java
com.remoteyourcam.usb.ptp.PtpUsbService.java
com.remoteyourcam.usb.ptp.WorkerNotifier.java
com.remoteyourcam.usb.ptp.commands.CloseSessionCommand.java
com.remoteyourcam.usb.ptp.commands.Command.java
com.remoteyourcam.usb.ptp.commands.GetDeviceInfoCommand.java
com.remoteyourcam.usb.ptp.commands.GetDevicePropDescCommand.java
com.remoteyourcam.usb.ptp.commands.GetDevicePropValueCommand.java
com.remoteyourcam.usb.ptp.commands.GetObjectCommand.java
com.remoteyourcam.usb.ptp.commands.GetObjectHandlesCommand.java
com.remoteyourcam.usb.ptp.commands.GetObjectInfoCommand.java
com.remoteyourcam.usb.ptp.commands.GetStorageIdsCommand.java
com.remoteyourcam.usb.ptp.commands.GetStorageInfoCommand.java
com.remoteyourcam.usb.ptp.commands.GetStorageInfosAction.java
com.remoteyourcam.usb.ptp.commands.GetThumb.java
com.remoteyourcam.usb.ptp.commands.InitiateCaptureCommand.java
com.remoteyourcam.usb.ptp.commands.OpenSessionCommand.java
com.remoteyourcam.usb.ptp.commands.RetrieveAddedObjectInfoAction.java
com.remoteyourcam.usb.ptp.commands.RetrieveImageAction.java
com.remoteyourcam.usb.ptp.commands.RetrieveImageInfoAction.java
com.remoteyourcam.usb.ptp.commands.RetrievePictureAction.java
com.remoteyourcam.usb.ptp.commands.SetDevicePropValueCommand.java
com.remoteyourcam.usb.ptp.commands.SimpleCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosEventCheckCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosGetLiveViewPictureCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosOpenSessionAction.java
com.remoteyourcam.usb.ptp.commands.eos.EosSetExtendedEventInfoCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosSetLiveViewAction.java
com.remoteyourcam.usb.ptp.commands.eos.EosSetPcModeCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosSetPropertyCommand.java
com.remoteyourcam.usb.ptp.commands.eos.EosTakePictureCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonAfDriveCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonAfDriveDeviceReadyCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonCloseSessionAction.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonEventCheckCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonGetLiveViewImageAction.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonGetLiveViewImageCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonGetVendorPropCodesCommand.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonOpenSessionAction.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonStartLiveViewAction.java
com.remoteyourcam.usb.ptp.commands.nikon.NikonStopLiveViewAction.java
com.remoteyourcam.usb.ptp.model.DeviceInfo.java
com.remoteyourcam.usb.ptp.model.DevicePropDesc.java
com.remoteyourcam.usb.ptp.model.LiveViewData.java
com.remoteyourcam.usb.ptp.model.ObjectInfo.java
com.remoteyourcam.usb.ptp.model.StorageInfo.java
com.remoteyourcam.usb.util.DimenUtil.java
com.remoteyourcam.usb.util.NotificationIds.java
com.remoteyourcam.usb.util.PackageUtil.java
com.remoteyourcam.usb.view.AspectRatioImageView.java
com.remoteyourcam.usb.view.BaseFragment.java
com.remoteyourcam.usb.view.GalleryAdapter.java
com.remoteyourcam.usb.view.GalleryFragment.java
com.remoteyourcam.usb.view.PictureFragment.java
com.remoteyourcam.usb.view.SessionActivity.java
com.remoteyourcam.usb.view.SessionFragment.java
com.remoteyourcam.usb.view.SessionView.java
com.remoteyourcam.usb.view.StorageAdapter.java
com.remoteyourcam.usb.view.TabletSessionFragment.java
com.remoteyourcam.usb.view.ThumbnailAdapter.java
com.remoteyourcam.usb.view.WebViewDialogFragment.java