Java tutorial
/* * Copyright (C) 2018 AlexMofer * * 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 am.project.x.business.others.printer; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatDialog; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import java.util.Collection; import am.project.x.R; import am.project.x.utils.AlertDialogUtils; /** * ?? */ class PrinterBluetoothDialog extends AppCompatDialog implements PrinterDeviceViewHolder.OnHolderListener { private final OnDialogListener mListener; private final PrinterDeviceAdapter mAdapter = new PrinterDeviceAdapter(this); PrinterBluetoothDialog(@NonNull Context context, @NonNull OnDialogListener listener) { super(context, AlertDialogUtils.getAlertDialogTheme(context)); mListener = listener; setContentView(R.layout.dlg_printer_bluetooth); final RecyclerView bonded = findViewById(R.id.dpb_rv_bonded); if (bonded == null) return; final Drawable divider = ContextCompat.getDrawable(context, R.drawable.divider_common); if (divider != null) { final DividerItemDecoration decoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL); decoration.setDrawable(divider); bonded.addItemDecoration(decoration); } bonded.setLayoutManager(new LinearLayoutManager(context)); bonded.setAdapter(mAdapter); } void invalidateBondedBluetoothDevices(Collection<? extends BluetoothDevice> devices) { mAdapter.setDevices(devices); } @Override public void dismiss() { mAdapter.setDevices(null); super.dismiss(); } // Listener @Override public void onItemClicked(BluetoothDevice device) { mListener.onBluetoothDeviceSelect(device); dismiss(); } /** * ?? */ public interface OnDialogListener { /** * ? * * @param device ? */ void onBluetoothDeviceSelect(BluetoothDevice device); } }