Search in sources :

Example 1 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class TransactionActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transaction);
    mDatabase = new AccessDatabase(this);
    mTransactionFragment = (TransactionListFragment) getSupportFragmentManager().findFragmentById(R.id.activity_transaction_listfragment_transaction);
    mPathView = findViewById(R.id.activity_transaction_explorer_recycler);
    mHomeButton = findViewById(R.id.activity_transaction_explorer_image_home);
    mPowafulActionMode = findViewById(R.id.activity_transaction_action_mode);
    // mPowafulActionMode.setContainerLayout(findViewById(R.id.activity_transaction_action_mode_container));
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mDrawerLayout = findViewById(R.id.drawer_layout);
    if (mDrawerLayout != null) {
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.text_navigationDrawerOpen, R.string.text_navigationDrawerClose);
        mDrawerLayout.addDrawerListener(toggle);
        toggle.syncState();
    }
    mNavigationView = findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    mPathView.setHasFixedSize(true);
    mFilter.addAction(AccessDatabase.ACTION_DATABASE_CHANGE);
    mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mPathAdapter = new TransactionPathResolverRecyclerAdapter();
    mPathView.setLayoutManager(mLayoutManager);
    mLayoutManager.setStackFromEnd(true);
    mPathView.setAdapter(mPathAdapter);
    mPowafulActionMode.setOnSelectionTaskListener(new PowerfulActionMode.OnSelectionTaskListener() {

        @Override
        public void onSelectionTask(boolean started, PowerfulActionMode actionMode) {
            toolbar.setVisibility(!started ? View.VISIBLE : View.GONE);
        }
    });
    mPathAdapter.setOnClickListener(new PathResolverRecyclerAdapter.OnClickListener<String>() {

        @Override
        public void onClick(PathResolverRecyclerAdapter.Holder<String> holder) {
            goPath(holder.index.object);
        }
    });
    mHomeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            goPath(null);
        }
    });
    if (ACTION_LIST_TRANSFERS.equals(getIntent().getAction()) && getIntent().hasExtra(EXTRA_GROUP_ID)) {
        TransactionObject.Group group = new TransactionObject.Group(getIntent().getIntExtra(EXTRA_GROUP_ID, -1));
        try {
            mDatabase.reconstruct(group);
            NetworkDevice networkDevice = new NetworkDevice(group.deviceId);
            mDatabase.reconstruct(networkDevice);
            mGroup = group;
            mDevice = networkDevice;
            mInfoDialog = new TransactionGroupInfoDialog(this, mDatabase, mGroup);
            if (getSupportActionBar() != null)
                getSupportActionBar().setTitle(mDevice.nickname);
            mTransactionFragment.getAdapter().setPathChangedListener(this);
            applyPath(null);
            View headerView = mNavigationView.getHeaderView(0);
            View layoutView = headerView.findViewById(R.id.header_default_device_container);
            ImageView imageView = headerView.findViewById(R.id.header_default_device_image);
            TextView deviceNameText = headerView.findViewById(R.id.header_default_device_name_text);
            TextView versionText = headerView.findViewById(R.id.header_default_device_version_text);
            String firstLetters = TextUtils.getFirstLetters(mDevice.nickname, 1);
            TextDrawable drawable = TextDrawable.builder().buildRoundRect(firstLetters.length() > 0 ? firstLetters : "?", ContextCompat.getColor(getApplicationContext(), R.color.networkDeviceRipple), 100);
            layoutView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    new DeviceInfoDialog(TransactionActivity.this, mDatabase, mDevice).show();
                    if (mDrawerLayout != null)
                        mDrawerLayout.closeDrawer(Gravity.START);
                }
            });
            imageView.setImageDrawable(drawable);
            deviceNameText.setText(mDevice.nickname);
            versionText.setText(mDevice.versionName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (mGroup == null)
        finish();
}
Also used : TextDrawable(com.amulyakhare.textdrawable.TextDrawable) NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TransactionObject(com.genonbeta.TrebleShot.object.TransactionObject) TransactionGroupInfoDialog(com.genonbeta.TrebleShot.dialog.TransactionGroupInfoDialog) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar) PowerfulActionMode(com.genonbeta.TrebleShot.widget.PowerfulActionMode) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) IOException(java.io.IOException) PathResolverRecyclerAdapter(com.genonbeta.TrebleShot.adapter.PathResolverRecyclerAdapter) DeviceInfoDialog(com.genonbeta.TrebleShot.dialog.DeviceInfoDialog) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase)

Example 2 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class TextEditorActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getIntent() == null || !ACTION_EDIT_TEXT.equals(getIntent().getAction()))
        finish();
    else {
        setContentView(R.layout.layout_text_editor_activity);
        if (getSupportActionBar() != null)
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mDatabase = new AccessDatabase(this);
        mEditTextEditor = findViewById(R.id.layout_text_editor_activity_text_text_box);
        if (getIntent().hasExtra(EXTRA_CLIPBOARD_ID)) {
            mTextStreamObject = new TextStreamObject(getIntent().getIntExtra(EXTRA_CLIPBOARD_ID, -1));
            try {
                mDatabase.reconstruct(mTextStreamObject);
                mEditTextEditor.getText().append(mTextStreamObject.text);
            } catch (Exception e) {
                e.printStackTrace();
                mTextStreamObject = null;
            }
        } else if (getIntent().hasExtra(EXTRA_TEXT_INDEX))
            mEditTextEditor.getText().append(getIntent().getStringExtra(EXTRA_TEXT_INDEX));
    }
}
Also used : TextStreamObject(com.genonbeta.TrebleShot.object.TextStreamObject) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase)

Example 3 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class ShareActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_share);
    if (getSupportActionBar() != null)
        getSupportActionBar().setTitle(R.string.text_shareWithTrebleshot);
    mFAB = findViewById(R.id.content_fab);
    mDatabase = new AccessDatabase(getApplicationContext());
    mDeviceListFragment = (NetworkDeviceListFragment) getSupportFragmentManager().findFragmentById(R.id.activity_share_fragment);
    mFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    mDeviceListFragment.getListView().setPadding(0, 0, 0, 300);
    mDeviceListFragment.getListView().setClipToPadding(false);
    mFAB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            fabClicked();
        }
    });
    mDeviceListFragment.setOnListClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            NetworkDevice device = (NetworkDevice) mDeviceListFragment.getListAdapter().getItem(position);
            if (device instanceof NetworkDeviceListAdapter.HotspotNetwork)
                doCommunicate((NetworkDeviceListAdapter.HotspotNetwork) device);
            else
                showChooserDialog(device);
        }
    });
    bindService(new Intent(this, WorkerService.class), mWorkerConnection, Context.BIND_AUTO_CREATE);
}
Also used : NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) WorkerService(com.genonbeta.TrebleShot.service.WorkerService) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase) NetworkDeviceListAdapter(com.genonbeta.TrebleShot.adapter.NetworkDeviceListAdapter) AdapterView(android.widget.AdapterView)

Example 4 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class ShareActivity method doCommunicate.

protected void doCommunicate(final NetworkDeviceListAdapter.HotspotNetwork hotspotNetwork) {
    resetProgressItems();
    getProgressDialog().setMessage(getString(R.string.mesg_connectingToSelfHotspot));
    getProgressDialog().setMax(20);
    getProgressDialog().show();
    runOnWorkerService(new WorkerService.RunningTask(TAG, WORKER_TASK_CONNECT_TS_NETWORK) {

        private boolean mConnected = false;

        private boolean mConnectionToggled = false;

        private long mStartTime = System.currentTimeMillis();

        private String mRemoteAddress;

        @Override
        public void onRun() {
            while (mRemoteAddress == null) {
                int passedTime = (int) (System.currentTimeMillis() - mStartTime);
                if (!mDeviceListFragment.getWifiManager().isWifiEnabled()) {
                    if (!mDeviceListFragment.getWifiManager().setWifiEnabled(true))
                        // failed to start Wireless
                        break;
                } else if (!mDeviceListFragment.isConnectedToNetwork(hotspotNetwork) && !mConnectionToggled) {
                    mConnectionToggled = mDeviceListFragment.toggleConnection(hotspotNetwork);
                } else {
                    for (AddressedInterface addressedInterface : NetworkUtils.getInterfaces(true, null)) {
                        if (addressedInterface.getNetworkInterface().getDisplayName().startsWith(AppConfig.NETWORK_INTERFACE_WIFI)) {
                            String remoteAddress = NetworkUtils.getAddressPrefix(addressedInterface.getAssociatedAddress()) + "1";
                            if (NetworkUtils.ping(remoteAddress, 1000)) {
                                mRemoteAddress = remoteAddress;
                                break;
                            }
                        }
                    }
                }
                if (interruptionCheck(passedTime))
                    break;
            }
            if (mRemoteAddress != null) {
                try {
                    NetworkDeviceLoader.load(true, mDatabase, mRemoteAddress, new NetworkDeviceLoader.OnDeviceRegisteredErrorListener() {

                        @Override
                        public void onError(Exception error) {
                            getProgressDialog().dismiss();
                        }

                        @Override
                        public void onDeviceRegistered(AccessDatabase database, NetworkDevice device, final NetworkDevice.Connection connection) {
                            mConnected = true;
                            try {
                                hotspotNetwork.deviceId = device.deviceId;
                                mDatabase.reconstruct(hotspotNetwork);
                                device = hotspotNetwork;
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            final NetworkDevice finalDevice = device;
                            if (!getDefaultInterrupter().interrupted())
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        getProgressDialog().dismiss();
                                        doCommunicate(finalDevice, connection);
                                    }
                                });
                        }
                    });
                } catch (ConnectException e) {
                    e.printStackTrace();
                }
            }
            if (!mConnected) {
                getProgressDialog().dismiss();
                createSnackbar(R.string.mesg_connectionFailure).show();
            }
        // We can't add dialog outside of the else statement as it may close other dialogs as well
        }

        private boolean interruptionCheck(int passedTime) {
            try {
                Thread.sleep(1000);
                getProgressDialog().setProgress(passedTime / 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                return true;
            } finally {
                if (passedTime > 20000 || getDefaultInterrupter().interrupted())
                    return true;
            }
            return false;
        }
    });
}
Also used : NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice) ServiceConnection(android.content.ServiceConnection) WorkerService(com.genonbeta.TrebleShot.service.WorkerService) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) AddressedInterface(com.genonbeta.TrebleShot.util.AddressedInterface) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase) ConnectException(java.net.ConnectException)

Example 5 with AccessDatabase

use of com.genonbeta.TrebleShot.database.AccessDatabase in project TrebleShot by genonbeta.

the class DeviceScannerService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mDatabase = new AccessDatabase(getApplicationContext());
}
Also used : AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase)

Aggregations

AccessDatabase (com.genonbeta.TrebleShot.database.AccessDatabase)11 View (android.view.View)4 NetworkDevice (com.genonbeta.TrebleShot.object.NetworkDevice)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 TextDrawable (com.amulyakhare.textdrawable.TextDrawable)2 PathResolverRecyclerAdapter (com.genonbeta.TrebleShot.adapter.PathResolverRecyclerAdapter)2 WorkerService (com.genonbeta.TrebleShot.service.WorkerService)2 IOException (java.io.IOException)2 Intent (android.content.Intent)1 ServiceConnection (android.content.ServiceConnection)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 MediaScannerConnection (android.media.MediaScannerConnection)1 Bundle (android.os.Bundle)1 ChooserTarget (android.service.chooser.ChooserTarget)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 NavigationView (android.support.design.widget.NavigationView)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1